home *** CD-ROM | disk | FTP | other *** search
MacBinary | 1994-03-22 | 36.4 KB | [ TEXT/R*ch]
open in: MacOS 8.1
extracted
|
Win98
extracted
|
DOS
extracted
view JSON data
|
view as text
This file was processed as: MacBinary
(archive/macBinary ).
You can browse this item here: The Swarm.c
Confidence Program Detection Match Type Support
66%
dexvert
Compact Compressed (Unix) (archive/compact)
ext
Supported
10%
dexvert
MacBinary (archive/macBinary)
fallback
Supported
1%
dexvert
Text File (text/txt)
fallback
Supported
100%
file
MacBinary II, Tue Mar 22 22:38:22 1994, modified Tue Mar 22 22:38:22 1994, creator BBEdit, type ASCII, 36573 bytes "The Swarm.c" , at 0x8f5d 416 bytes resource
default (weak)
99%
file
data
default
74%
TrID
Macintosh plain text (MacBinary)
default
25%
TrID
MacBinary 2
default (weak)
100%
siegfried
fmt/1762 MacBinary (II)
default
100%
lsar
MacBinary
default
id metadata key value macFileType [ TEXT] macFileCreator [ R*ch]
hex view +--------+-------------------------+-------------------------+--------+--------+ |00000000| 00 0b 54 68 65 20 53 77 | 61 72 6d 2e 63 00 00 00 |..The Sw|arm.c...| |00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........| |00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........| |00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........| |00000040| 00 54 45 58 54 52 2a 63 | 68 00 00 00 00 00 00 00 |.TEXTR*c|h.......| |00000050| 00 00 00 00 00 8e dd 00 | 00 01 a0 a9 b5 6a 2e a9 |........|.....j..| |00000060| b5 6a 2e 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |.j......|........| |00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 a5 77 00 00 |........|.....w..| |00000080| 2f 2a 0d 20 2a 20 20 20 | 20 54 68 65 20 53 77 61 |/*. * | The Swa| |00000090| 72 6d 20 31 2e 30 20 2d | 20 61 6e 20 41 66 74 65 |rm 1.0 -| an Afte| |000000a0| 72 20 44 61 72 6b 20 6d | 6f 64 75 6c 65 20 62 79 |r Dark m|odule by| |000000b0| 20 4c 65 6f 20 42 72 65 | 65 62 61 61 72 74 2c 20 | Leo Bre|ebaart, | |000000c0| 4b 72 6f 6e 74 6f 20 53 | 6f 66 74 77 61 72 65 20 |Kronto S|oftware | |000000d0| 31 39 39 34 2e 0d 20 2a | 0d 20 2a 0d 20 2a 09 20 |1994.. *|. *. *. | |000000e0| 20 46 6f 72 20 6e 6f 6e | 2d 74 65 63 68 6e 69 63 | For non|-technic| |000000f0| 61 6c 20 69 6e 66 6f 72 | 6d 61 74 69 6f 6e 20 61 |al infor|mation a| |00000100| 62 6f 75 74 20 74 68 69 | 73 20 6d 6f 64 75 6c 65 |bout thi|s module| |00000110| 20 61 6e 64 20 66 6f 72 | 20 74 68 65 20 63 72 65 | and for| the cre| |00000120| 64 69 74 73 2c 0d 20 2a | 20 20 20 20 73 65 65 20 |dits,. *| see | |00000130| 74 68 65 20 52 45 41 44 | 4d 45 20 66 69 6c 65 2e |the READ|ME file.| |00000140| 0d 20 2a 20 09 20 20 0d | 20 2a 20 09 20 20 54 68 |. * . .| * . Th| |00000150| 69 73 20 6d 6f 64 75 6c | 65 20 64 69 73 70 6c 61 |is modul|e displa| |00000160| 79 73 20 61 20 76 61 72 | 69 61 62 6c 65 20 6e 75 |ys a var|iable nu| |00000170| 6d 62 65 72 20 6f 66 20 | 6c 69 6e 65 2d 73 65 67 |mber of |line-seg| |00000180| 6d 65 6e 74 73 20 28 74 | 68 65 20 d4 42 65 65 73 |ments (t|he .Bees| |00000190| d5 29 2c 20 77 68 69 63 | 68 20 0d 20 2a 20 09 20 |.), whic|h . * . | |000001a0| 20 63 68 61 73 65 20 61 | 6e 6f 74 68 65 72 20 6c | chase a|nother l| |000001b0| 69 6e 65 20 73 65 67 6d | 65 6e 74 20 28 74 68 65 |ine segm|ent (the| |000001c0| 20 d4 51 75 65 65 6e d5 | 29 20 61 63 72 6f 73 73 | .Queen.|) across| |000001d0| 20 74 68 65 20 73 63 72 | 65 65 6e 2e 0d 20 2a 20 | the scr|een.. * | |000001e0| 09 20 20 0d 20 2a 20 09 | 20 20 49 20 68 61 76 65 |. . * .| I have| |000001f0| 20 63 6f 6d 6d 65 6e 74 | 65 64 20 74 68 65 20 63 | comment|ed the c| |00000200| 6f 64 65 20 69 6e 20 61 | 20 77 61 79 20 74 68 61 |ode in a| way tha| |00000210| 74 20 65 78 70 65 72 69 | 65 6e 63 65 64 20 70 72 |t experi|enced pr| |00000220| 6f 67 72 61 6d 6d 65 72 | 73 20 6d 61 79 20 66 69 |ogrammer|s may fi| |00000230| 6e 64 0d 20 2a 20 09 20 | 20 6f 76 65 72 6b 69 6c |nd. * . | overkil| |00000240| 6c 2c 20 62 75 74 20 69 | 74 20 77 61 73 20 64 6f |l, but i|t was do| |00000250| 6e 65 20 69 6e 20 74 68 | 65 20 68 6f 70 65 20 74 |ne in th|e hope t| |00000260| 68 61 74 20 62 65 67 69 | 6e 6e 69 6e 67 20 41 66 |hat begi|nning Af| |00000270| 74 65 72 20 44 61 72 6b | 20 70 72 6f 67 72 61 6d |ter Dark| program| |00000280| 6d 65 72 73 0d 20 2a 20 | 09 20 20 77 69 6c 6c 20 |mers. * |. will | |00000290| 66 69 6e 64 20 d2 54 68 | 65 20 53 77 61 72 6d d3 |find .Th|e Swarm.| |000002a0| 20 61 20 75 73 65 66 75 | 6c 20 73 74 61 72 74 69 | a usefu|l starti| |000002b0| 6e 67 20 70 6f 69 6e 74 | 20 66 6f 72 20 77 72 69 |ng point| for wri| |000002c0| 74 69 6e 67 20 74 68 65 | 69 72 20 6f 77 6e 20 0d |ting the|ir own .| |000002d0| 20 2a 20 09 20 20 6d 6f | 64 75 6c 65 73 2e 0d 20 | * . mo|dules.. | |000002e0| 2a 20 09 20 20 0d 20 2a | 20 09 20 20 46 6f 72 20 |* . . *| . For | |000002f0| 67 65 6e 65 72 61 6c 20 | 69 6e 66 6f 72 6d 61 74 |general |informat| |00000300| 69 6f 6e 20 61 62 6f 75 | 74 20 68 6f 77 20 74 6f |ion abou|t how to| |00000310| 20 77 72 69 74 65 20 61 | 6e 20 41 66 74 65 72 20 | write a|n After | |00000320| 44 61 72 6b 20 6d 6f 64 | 75 6c 65 2c 20 0d 20 2a |Dark mod|ule, . *| |00000330| 20 09 20 20 73 65 65 20 | 74 68 65 20 41 66 74 65 | . see |the Afte| |00000340| 72 20 44 61 72 6b 20 50 | 72 6f 67 72 61 6d 6d 65 |r Dark P|rogramme| |00000350| 72 d5 73 20 4d 61 6e 75 | 61 6c 2c 20 62 75 74 20 |r.s Manu|al, but | |00000360| 6d 61 6b 65 20 73 75 72 | 65 20 79 6f 75 20 68 61 |make sur|e you ha| |00000370| 76 65 20 74 68 65 20 6d | 6f 73 74 20 72 65 63 65 |ve the m|ost rece| |00000380| 6e 74 0d 20 2a 20 09 20 | 20 76 65 72 73 69 6f 6e |nt. * . | version| |00000390| 20 28 72 65 6c 65 61 73 | 65 64 20 77 69 74 68 20 | (releas|ed with | |000003a0| 41 66 74 65 72 20 44 61 | 72 6b 20 32 2e 30 75 20 |After Da|rk 2.0u | |000003b0| 61 6e 64 20 6c 61 74 65 | 72 29 2e 20 54 68 65 20 |and late|r). The | |000003c0| 63 6f 6d 6d 65 6e 74 73 | 20 69 6e 20 74 68 69 73 |comments| in this| |000003d0| 0d 20 2a 20 20 20 20 6d | 6f 64 75 6c 65 20 64 6f |. * m|odule do| |000003e0| 20 61 73 73 75 6d 65 20 | 79 6f 75 20 61 72 65 20 | assume |you are | |000003f0| 61 74 20 6c 65 61 73 74 | 20 2a 61 77 61 72 65 2a |at least| *aware*| |00000400| 20 6f 66 20 74 68 65 20 | 62 61 73 69 63 20 41 66 | of the |basic Af| |00000410| 74 65 72 20 44 61 72 6b | 20 6d 65 63 68 61 6e 69 |ter Dark| mechani| |00000420| 73 6d 73 2e 0d 20 2a 0d | 20 2a 09 20 20 48 65 72 |sms.. *.| *. Her| |00000430| 65 20 77 65 20 67 6f 2e | 2e 2e 0d 20 2a 2f 0d 20 |e we go.|... */. | |00000440| 0d 23 69 6e 63 6c 75 64 | 65 20 3c 51 44 6f 66 66 |.#includ|e <QDoff| |00000450| 73 63 72 65 65 6e 2e 68 | 3e 0d 0d 23 69 6e 63 6c |screen.h|>..#incl| |00000460| 75 64 65 20 22 41 66 74 | 65 72 44 61 72 6b 54 79 |ude "Aft|erDarkTy| |00000470| 70 65 73 2e 68 22 0d 09 | 0d 09 2f 2f 20 49 6e 74 |pes.h"..|..// Int| |00000480| 65 72 66 61 63 65 20 74 | 6f 20 4a 6f 6e 61 73 20 |erface t|o Jonas | |00000490| 45 6e 67 6c 75 6e 64 27 | 73 20 43 4c 55 54 20 66 |Englund'|s CLUT f| |000004a0| 61 64 65 20 6c 69 62 72 | 61 72 79 20 66 6f 72 20 |ade libr|ary for | |000004b0| 6e 69 63 65 20 66 61 64 | 65 2d 69 6e 2f 66 61 64 |nice fad|e-in/fad| |000004c0| 65 2d 6f 75 74 20 65 66 | 66 65 63 74 73 2e 0d 23 |e-out ef|fects..#| |000004d0| 69 6e 63 6c 75 64 65 20 | 22 66 61 64 65 2e 68 22 |include |"fade.h"| |000004e0| 0d 0d 0d 09 2f 2f 20 43 | 6f 6e 73 74 61 6e 74 73 |....// C|onstants| |000004f0| 0d 23 64 65 66 69 6e 65 | 20 4d 41 58 42 45 45 53 |.#define| MAXBEES| |00000500| 20 31 30 30 09 09 09 2f | 2f 20 4d 61 78 69 6d 75 | 100.../|/ Maximu| |00000510| 6d 20 6e 75 6d 62 65 72 | 20 6f 66 20 42 65 65 73 |m number| of Bees| |00000520| 2e 0d 23 64 65 66 69 6e | 65 20 51 55 45 45 4e 56 |..#defin|e QUEENV| |00000530| 45 4c 20 31 32 09 09 09 | 2f 2f 20 4d 61 78 69 6d |EL 12...|// Maxim| |00000540| 75 6d 20 51 75 65 65 6e | 20 76 65 6c 6f 63 69 74 |um Queen| velocit| |00000550| 79 20 28 69 6e 20 70 69 | 78 65 6c 73 2c 20 61 73 |y (in pi|xels, as| |00000560| 20 61 72 65 20 74 68 65 | 20 6f 74 68 65 72 73 29 | are the| others)| |00000570| 2e 0d 23 64 65 66 69 6e | 65 20 51 55 45 45 4e 41 |..#defin|e QUEENA| |00000580| 43 43 20 35 09 09 09 2f | 2f 20 4d 61 78 69 6d 75 |CC 5.../|/ Maximu| |00000590| 6d 20 51 75 65 65 6e 20 | 61 63 63 65 6c 65 72 61 |m Queen |accelera| |000005a0| 74 69 6f 6e 2e 0d 23 64 | 65 66 69 6e 65 20 42 45 |tion..#d|efine BE| |000005b0| 45 56 45 4c 20 20 31 31 | 09 09 09 2f 2f 20 4d 61 |EVEL 11|...// Ma| |000005c0| 78 69 6d 75 6d 20 42 65 | 65 20 76 65 6c 6f 63 69 |ximum Be|e veloci| |000005d0| 74 79 2e 0d 23 64 65 66 | 69 6e 65 20 42 45 45 41 |ty..#def|ine BEEA| |000005e0| 43 43 20 20 33 09 09 09 | 2f 2f 20 4d 61 78 69 6d |CC 3...|// Maxim| |000005f0| 75 6d 20 42 65 65 20 61 | 63 63 65 6c 65 72 61 74 |um Bee a|ccelerat| |00000600| 69 6f 6e 2e 0d 23 64 65 | 66 69 6e 65 20 42 4f 52 |ion..#de|fine BOR| |00000610| 44 45 52 20 20 35 30 09 | 09 09 2f 2f 20 51 75 65 |DER 50.|..// Que| |00000620| 65 6e 20 77 6f 6e 27 74 | 20 67 6f 20 61 6e 79 20 |en won't| go any | |00000630| 6e 65 61 72 65 72 20 74 | 68 61 6e 20 74 68 69 73 |nearer t|han this| |00000640| 20 6d 61 6e 79 20 70 69 | 78 65 6c 73 20 74 6f 20 | many pi|xels to | |00000650| 74 68 65 0d 09 09 09 09 | 09 09 09 2f 2f 20 65 64 |the.....|...// ed| |00000660| 67 65 20 6f 66 20 74 68 | 65 20 73 63 72 65 65 6e |ge of th|e screen| |00000670| 20 61 6e 64 20 74 68 65 | 20 64 65 6d 6f 20 72 65 | and the| demo re| |00000680| 63 74 61 6e 67 6c 65 2e | 0d 09 09 09 09 09 09 0d |ctangle.|........| |00000690| 09 2f 2f 20 44 61 74 61 | 20 73 74 72 75 63 74 75 |.// Data| structu| |000006a0| 72 65 73 0d 74 79 70 65 | 64 65 66 20 69 6e 74 09 |res.type|def int.| |000006b0| 2a 2a 49 6e 74 48 61 6e | 64 6c 65 3b 09 09 2f 2f |**IntHan|dle;..//| |000006c0| 20 4f 75 72 20 42 65 65 | 20 70 6f 73 69 74 69 6f | Our Bee| positio| |000006d0| 6e 20 61 72 72 61 79 73 | 20 77 69 6c 6c 20 62 65 |n arrays| will be| |000006e0| 20 64 79 6e 61 6d 69 63 | 61 6c 20 61 72 72 61 79 | dynamic|al array| |000006f0| 73 0d 09 09 09 09 09 09 | 09 09 2f 2f 20 61 6c 6c |s.......|..// all| |00000700| 6f 63 61 74 65 64 20 75 | 73 69 6e 67 20 68 61 6e |ocated u|sing han| |00000710| 64 6c 65 73 2e 0d 0d 74 | 79 70 65 64 65 66 20 73 |dles...t|ypedef s| |00000720| 74 72 75 63 74 20 53 77 | 61 72 6d 53 74 6f 72 61 |truct Sw|armStora| |00000730| 67 65 09 09 2f 2f 20 41 | 6c 6c 20 64 61 74 61 20 |ge..// A|ll data | |00000740| 77 65 20 75 73 65 20 69 | 73 20 73 74 6f 72 65 64 |we use i|s stored| |00000750| 20 69 6e 20 74 68 69 73 | 20 73 74 72 75 63 74 2e | in this| struct.| |00000760| 0d 7b 0d 20 20 20 20 69 | 6e 74 20 71 75 65 65 6e |.{. i|nt queen| |00000770| 58 5b 32 5d 2c 20 71 75 | 65 65 6e 59 5b 32 5d 3b |X[2], qu|eenY[2];| |00000780| 09 09 2f 2f 20 53 74 6f | 72 61 67 65 20 66 6f 72 |..// Sto|rage for| |00000790| 20 51 75 65 65 6e 20 6c | 69 6e 65 20 73 65 67 6d | Queen l|ine segm| |000007a0| 65 6e 74 2e 0d 20 20 20 | 20 69 6e 74 20 71 75 65 |ent.. | int que| |000007b0| 65 6e 56 65 6c 58 2c 20 | 71 75 65 65 6e 56 65 6c |enVelX, |queenVel| |000007c0| 59 3b 09 09 2f 2f 20 43 | 75 72 72 65 6e 74 20 51 |Y;..// C|urrent Q| |000007d0| 75 65 65 6e 20 76 65 6c | 6f 63 69 74 79 20 63 6f |ueen vel|ocity co| |000007e0| 6d 70 6f 6e 65 6e 74 73 | 2e 0d 20 20 20 20 49 6e |mponents|.. In| |000007f0| 74 48 61 6e 64 6c 65 20 | 62 65 65 58 5b 32 5d 2c |tHandle |beeX[2],| |00000800| 20 62 65 65 59 5b 32 5d | 3b 09 09 2f 2f 20 44 79 | beeY[2]|;..// Dy| |00000810| 6e 61 6d 69 63 20 73 74 | 6f 72 61 67 65 20 66 6f |namic st|orage fo| |00000820| 72 20 42 65 65 20 6c 69 | 6e 65 20 73 65 67 6d 65 |r Bee li|ne segme| |00000830| 6e 74 73 2e 0d 20 20 20 | 20 49 6e 74 48 61 6e 64 |nts.. | IntHand| |00000840| 6c 65 20 62 65 65 56 65 | 6c 58 2c 20 62 65 65 56 |le beeVe|lX, beeV| |00000850| 65 6c 59 3b 09 09 2f 2f | 20 44 79 6e 61 6d 69 63 |elY;..//| Dynamic| |00000860| 20 73 74 6f 72 61 67 65 | 20 66 6f 72 20 42 65 65 | storage| for Bee| |00000870| 20 76 65 6c 6f 63 69 74 | 69 65 73 20 63 6f 6d 70 | velocit|ies comp| |00000880| 6f 6e 65 6e 74 73 2e 0d | 0d 20 20 20 20 52 65 63 |onents..|. Rec| |00000890| 74 20 73 77 61 72 6d 52 | 65 63 74 3b 20 09 09 09 |t swarmR|ect; ...| |000008a0| 09 2f 2f 20 42 6f 75 6e | 64 69 6e 67 20 72 65 63 |.// Boun|ding rec| |000008b0| 74 61 6e 67 6c 65 20 66 | 6f 72 20 73 77 61 72 6d |tangle f|or swarm| |000008c0| 20 61 74 20 74 69 6d 65 | 20 27 30 27 2e 0d 20 20 | at time| '0'.. | |000008d0| 20 20 52 65 63 74 20 6f | 6c 64 52 65 63 74 3b 09 | Rect o|ldRect;.| |000008e0| 09 09 09 09 2f 2f 20 42 | 6f 75 6e 64 69 6e 67 20 |....// B|ounding | |000008f0| 72 65 63 74 61 6e 67 6c | 65 20 66 6f 72 20 73 77 |rectangl|e for sw| |00000900| 61 72 6d 20 61 74 20 74 | 69 6d 65 20 27 31 27 2e |arm at t|ime '1'.| |00000910| 0d 20 20 20 20 0d 20 20 | 20 20 69 6e 74 20 6d 61 |. . | int ma| |00000920| 78 51 75 65 65 6e 56 65 | 6c 2c 20 6d 61 78 42 65 |xQueenVe|l, maxBe| |00000930| 65 56 65 6c 3b 09 09 2f | 2f 20 54 68 65 73 65 20 |eVel;../|/ These | |00000940| 76 61 72 69 61 62 6c 65 | 73 20 73 74 6f 72 65 20 |variable|s store | |00000950| 74 68 65 20 63 6f 6e 73 | 74 61 6e 74 73 0d 20 20 |the cons|tants. | |00000960| 20 20 69 6e 74 20 6d 61 | 78 51 75 65 65 6e 41 63 | int ma|xQueenAc| |00000970| 63 2c 20 6d 61 78 42 65 | 65 41 63 63 3b 09 09 2f |c, maxBe|eAcc;../| |00000980| 2f 20 64 65 66 69 6e 65 | 64 20 65 61 72 6c 69 65 |/ define|d earlie| |00000990| 72 2e 0d 20 20 20 20 69 | 6e 74 20 62 6f 72 64 65 |r.. i|nt borde| |000009a0| 72 3b 09 09 09 09 0d 20 | 20 20 20 0d 20 20 20 20 |r;..... | . | |000009b0| 69 6e 74 20 6e 42 65 65 | 73 3b 09 09 09 09 09 09 |int nBee|s;......| |000009c0| 2f 2f 20 54 68 65 20 63 | 75 72 72 65 6e 74 20 6e |// The c|urrent n| |000009d0| 75 6d 62 65 72 20 6f 66 | 20 61 63 74 69 76 65 20 |umber of| active | |000009e0| 42 65 65 73 2e 0d 20 20 | 20 20 6c 6f 6e 67 20 64 |Bees.. | long d| |000009f0| 65 6c 61 79 3b 09 09 09 | 09 09 09 2f 2f 20 54 68 |elay;...|...// Th| |00000a00| 65 20 63 75 72 72 65 6e | 74 20 61 6e 69 6d 61 74 |e curren|t animat| |00000a10| 69 6f 6e 20 73 70 65 65 | 64 20 64 65 70 65 6e 64 |ion spee|d depend| |00000a20| 73 20 6f 6e 20 74 68 69 | 73 20 76 61 6c 75 65 2e |s on thi|s value.| |00000a30| 0d 20 20 20 20 6c 6f 6e | 67 20 73 74 61 72 74 44 |. lon|g startD| |00000a40| 72 61 77 69 6e 67 3b 09 | 09 09 09 2f 2f 20 57 6f |rawing;.|...// Wo| |00000a50| 72 6b 73 20 74 6f 67 65 | 74 68 65 72 20 77 69 74 |rks toge|ther wit| |00000a60| 68 20 64 65 6c 61 79 20 | 74 6f 20 63 6f 6e 74 72 |h delay |to contr| |00000a70| 6f 6c 20 61 6e 69 6d 61 | 74 69 6f 6e 20 73 70 65 |ol anima|tion spe| |00000a80| 65 64 2e 0d 20 20 20 20 | 42 6f 6f 6c 65 61 6e 20 |ed.. |Boolean | |00000a90| 64 65 6d 6f 4d 6f 64 65 | 3b 09 09 09 09 2f 2f 20 |demoMode|;....// | |00000aa0| 41 72 65 20 77 65 20 63 | 75 72 72 65 6e 74 6c 79 |Are we c|urrently| |00000ab0| 20 69 6e 20 41 66 74 65 | 72 20 44 61 72 6b 20 64 | in Afte|r Dark d| |00000ac0| 65 6d 6f 20 4d 6f 64 65 | 3f 0d 0d 20 20 20 20 52 |emo Mode|?.. R| |00000ad0| 47 42 43 6f 6c 6f 72 20 | 77 68 69 74 65 52 47 42 |GBColor |whiteRGB| |00000ae0| 2c 20 62 6c 61 63 6b 52 | 47 42 3b 09 2f 2f 20 43 |, blackR|GB;.// C| |00000af0| 6f 6c 6f 72 20 51 75 69 | 63 6b 44 72 61 77 20 63 |olor Qui|ckDraw c| |00000b00| 6f 6c 6f 72 73 3a 20 77 | 68 69 74 65 20 61 6e 64 |olors: w|hite and| |00000b10| 20 62 6c 61 63 6b 2e 0d | 20 20 20 20 52 47 42 43 | black..| RGBC| |00000b20| 6f 6c 6f 72 20 71 75 65 | 65 6e 52 47 42 2c 20 62 |olor que|enRGB, b| |00000b30| 65 65 52 47 42 3b 09 09 | 2f 2f 20 43 6f 6c 6f 72 |eeRGB;..|// Color| |00000b40| 20 51 75 69 63 6b 44 72 | 61 77 20 63 6f 6c 6f 72 | QuickDr|aw color| |00000b50| 73 20 66 6f 72 20 51 75 | 65 65 6e 20 61 6e 64 20 |s for Qu|een and | |00000b60| 42 65 65 73 2e 0d 20 20 | 20 20 52 47 42 43 6f 6c |Bees.. | RGBCol| |00000b70| 6f 72 20 62 61 63 6b 52 | 47 42 3b 09 09 09 09 2f |or backR|GB;..../| |00000b80| 2f 20 43 6f 6c 6f 72 20 | 51 75 69 63 6b 44 72 61 |/ Color |QuickDra| |00000b90| 77 20 63 6f 6c 6f 72 20 | 66 6f 72 20 61 6e 69 6d |w color |for anim| |00000ba0| 61 74 69 6f 6e 20 62 61 | 63 6b 67 72 6f 75 6e 64 |ation ba|ckground| |00000bb0| 2e 0d 20 20 20 20 20 20 | 0d 20 20 20 20 52 65 63 |.. |. Rec| |00000bc0| 74 20 6d 6f 6e 69 74 6f | 72 52 65 63 74 3b 09 09 |t monito|rRect;..| |00000bd0| 09 09 2f 2f 20 52 65 63 | 74 61 6e 67 6c 65 20 63 |..// Rec|tangle c| |00000be0| 6f 72 72 65 73 70 6f 6e | 64 69 6e 67 20 74 6f 20 |orrespon|ding to | |00000bf0| 6d 61 69 6e 20 6d 6f 6e | 69 74 6f 72 2e 0d 20 20 |main mon|itor.. | |00000c00| 20 20 69 6e 74 20 77 69 | 6e 57 2c 20 77 69 6e 48 | int wi|nW, winH| |00000c10| 3b 09 09 09 09 09 2f 2f | 20 54 68 65 20 69 6e 66 |;.....//| The inf| |00000c20| 6f 20 61 62 6f 75 74 20 | 6d 6f 6e 69 74 6f 72 52 |o about |monitorR| |00000c30| 65 63 74 20 77 65 20 72 | 65 61 6c 6c 79 20 6e 65 |ect we r|eally ne| |00000c40| 65 64 2e 0d 0d 20 20 20 | 09 47 57 6f 72 6c 64 50 |ed... |.GWorldP| |00000c50| 74 72 20 67 4d 79 4f 66 | 66 47 3b 09 09 09 09 2f |tr gMyOf|fG;..../| |00000c60| 2f 20 41 20 70 6f 69 6e | 74 65 72 20 74 6f 20 61 |/ A poin|ter to a| |00000c70| 6e 20 6f 66 66 73 63 72 | 65 65 6e 20 67 72 61 70 |n offscr|een grap| |00000c80| 68 69 63 73 20 77 6f 72 | 6c 64 2e 0d 7d 0d 53 77 |hics wor|ld..}.Sw| |00000c90| 61 72 6d 53 74 6f 72 61 | 67 65 2c 20 2a 53 77 61 |armStora|ge, *Swa| |00000ca0| 72 6d 53 74 6f 72 61 67 | 65 50 74 72 3b 0d 0d 09 |rmStorag|ePtr;...| |00000cb0| 09 09 09 09 09 09 0d 09 | 2f 2f 20 48 65 72 65 20 |........|// Here | |00000cc0| 77 65 20 64 65 66 69 6e | 65 20 73 6f 6d 65 20 68 |we defin|e some h| |00000cd0| 61 6e 64 79 20 6d 61 63 | 72 6f 27 73 20 66 6f 72 |andy mac|ro's for| |00000ce0| 20 61 63 63 65 73 73 69 | 6e 67 20 74 68 65 20 0d | accessi|ng the .| |00000cf0| 09 2f 2f 20 53 77 61 72 | 6d 27 73 20 70 6f 73 69 |.// Swar|m's posi| |00000d00| 74 69 6f 6e 20 61 6e 64 | 20 76 65 6c 6f 63 69 74 |tion and| velocit| |00000d10| 79 20 76 61 6c 75 65 73 | 2e 20 54 68 65 73 65 20 |y values|. These | |00000d20| 6d 61 63 72 6f 27 73 20 | 77 6f 72 6b 20 75 6e 64 |macro's |work und| |00000d30| 65 72 20 74 68 65 0d 09 | 2f 2f 20 61 73 73 75 6d |er the..|// assum| |00000d40| 70 74 69 6f 6e 20 74 68 | 61 74 20 79 6f 75 20 68 |ption th|at you h| |00000d50| 61 76 65 20 61 20 68 61 | 6e 64 6c 65 20 76 61 72 |ave a ha|ndle var| |00000d60| 69 61 62 6c 65 20 6e 61 | 6d 65 64 20 27 73 77 61 |iable na|med 'swa| |00000d70| 72 6d 27 2c 20 70 6f 69 | 6e 74 69 6e 67 0d 09 2f |rm', poi|nting../| |00000d80| 2f 20 74 6f 20 61 20 73 | 74 6f 72 61 67 65 20 73 |/ to a s|torage s| |00000d90| 74 72 75 63 74 20 61 73 | 20 64 65 66 69 6e 65 64 |truct as| defined| |00000da0| 20 61 62 6f 76 65 2e 0d | 0d 09 2f 2f 20 50 6f 73 | above..|..// Pos| |00000db0| 69 74 69 6f 6e 20 6f 66 | 20 42 65 65 20 62 20 61 |ition of| Bee b a| |00000dc0| 74 20 74 69 6d 65 20 74 | 20 28 65 69 74 68 65 72 |t time t| (either| |00000dd0| 20 30 20 6f 72 20 31 29 | 2e 0d 23 64 65 66 69 6e | 0 or 1)|..#defin| |00000de0| 65 20 42 58 28 74 2c 62 | 29 20 20 28 2a 28 28 2a |e BX(t,b|) (*((*| |00000df0| 28 73 77 61 72 6d 2d 3e | 62 65 65 58 5b 74 5d 29 |(swarm->|beeX[t])| |00000e00| 29 2b 28 62 29 29 29 0d | 23 64 65 66 69 6e 65 20 |)+(b))).|#define | |00000e10| 42 59 28 74 2c 62 29 20 | 20 28 2a 28 28 2a 28 73 |BY(t,b) | (*((*(s| |00000e20| 77 61 72 6d 2d 3e 62 65 | 65 59 5b 74 5d 29 29 2b |warm->be|eY[t]))+| |00000e30| 28 62 29 29 29 0d 0d 09 | 2f 2f 20 43 75 72 72 65 |(b)))...|// Curre| |00000e40| 6e 74 20 76 65 6c 6f 63 | 69 74 79 20 6f 66 20 42 |nt veloc|ity of B| |00000e50| 65 65 20 62 0d 23 64 65 | 66 69 6e 65 20 42 58 56 |ee b.#de|fine BXV| |00000e60| 28 62 29 09 28 2a 28 28 | 2a 73 77 61 72 6d 2d 3e |(b).(*((|*swarm->| |00000e70| 62 65 65 56 65 6c 58 29 | 2b 28 62 29 29 29 0d 23 |beeVelX)|+(b))).#| |00000e80| 64 65 66 69 6e 65 20 42 | 59 56 28 62 29 09 28 2a |define B|YV(b).(*| |00000e90| 28 28 2a 73 77 61 72 6d | 2d 3e 62 65 65 56 65 6c |((*swarm|->beeVel| |00000ea0| 59 29 2b 28 62 29 29 29 | 0d 0d 09 2f 2f 20 50 6f |Y)+(b)))|...// Po| |00000eb0| 73 69 74 69 6f 6e 20 6f | 66 20 51 75 65 65 6e 20 |sition o|f Queen | |00000ec0| 61 74 20 74 69 6d 65 20 | 74 20 28 65 69 74 68 65 |at time |t (eithe| |00000ed0| 72 20 30 20 6f 72 20 31 | 29 2e 0d 23 64 65 66 69 |r 0 or 1|)..#defi| |00000ee0| 6e 65 20 51 58 28 74 29 | 20 20 28 73 77 61 72 6d |ne QX(t)| (swarm| |00000ef0| 2d 3e 71 75 65 65 6e 58 | 5b 74 5d 29 0d 23 64 65 |->queenX|[t]).#de| |00000f00| 66 69 6e 65 20 51 59 28 | 74 29 20 20 28 73 77 61 |fine QY(|t) (swa| |00000f10| 72 6d 2d 3e 71 75 65 65 | 6e 59 5b 74 5d 29 0d 0d |rm->quee|nY[t])..| |00000f20| 09 2f 2f 20 43 75 72 72 | 65 6e 74 20 76 65 6c 6f |.// Curr|ent velo| |00000f30| 63 69 74 79 20 6f 66 20 | 51 75 65 65 6e 0d 23 64 |city of |Queen.#d| |00000f40| 65 66 69 6e 65 20 51 58 | 56 09 28 73 77 61 72 6d |efine QX|V.(swarm| |00000f50| 2d 3e 71 75 65 65 6e 56 | 65 6c 58 29 0d 23 64 65 |->queenV|elX).#de| |00000f60| 66 69 6e 65 20 51 59 56 | 09 28 73 77 61 72 6d 2d |fine QYV|.(swarm-| |00000f70| 3e 71 75 65 65 6e 56 65 | 6c 59 29 0d 0d 09 2f 2f |>queenVe|lY)...//| |00000f80| 20 41 20 63 6f 6d 6d 65 | 6e 74 20 61 62 6f 75 74 | A comme|nt about| |00000f90| 20 74 68 69 73 20 27 74 | 69 6d 65 20 74 27 20 62 | this 't|ime t' b| |00000fa0| 75 73 69 6e 65 73 73 3a | 20 65 61 63 68 20 73 77 |usiness:| each sw| |00000fb0| 61 72 6d 20 6d 65 6d 62 | 65 72 27 73 0d 09 2f 2f |arm memb|er's..//| |00000fc0| 20 6c 69 6e 65 20 73 65 | 67 6d 65 6e 74 20 69 73 | line se|gment is| |00000fd0| 20 64 72 61 77 6e 20 27 | 66 72 6f 6d 27 20 70 6f | drawn '|from' po| |00000fe0| 73 69 74 69 6f 6e 20 30 | 20 74 6f 20 70 6f 73 69 |sition 0| to posi| |00000ff0| 74 69 6f 6e 20 31 2e 20 | 53 6f 0d 09 2f 2f 20 74 |tion 1. |So..// t| |00001000| 3d 31 20 69 73 20 74 68 | 65 20 27 6f 6c 64 27 20 |=1 is th|e 'old' | |00001010| 70 6f 73 69 74 69 6f 6e | 2c 20 74 3d 30 20 74 68 |position|, t=0 th| |00001020| 65 20 27 6e 65 77 27 20 | 70 6f 73 69 74 69 6f 6e |e 'new' |position| |00001030| 2e 20 41 66 74 65 72 20 | 6f 6e 65 0d 09 2f 2f 20 |. After |one..// | |00001040| 66 72 61 6d 65 20 6f 66 | 20 61 6e 69 6d 61 74 69 |frame of| animati| |00001050| 6f 6e 2c 20 65 2e 67 2e | 20 51 58 28 30 29 20 77 |on, e.g.| QX(0) w| |00001060| 69 6c 6c 20 62 65 20 61 | 73 73 69 67 6e 65 64 20 |ill be a|ssigned | |00001070| 74 6f 20 51 58 28 31 29 | 20 28 6d 61 6b 69 6e 67 |to QX(1)| (making| |00001080| 0d 09 2f 2f 20 74 68 61 | 74 20 74 68 65 20 27 6f |..// tha|t the 'o| |00001090| 6c 64 27 20 70 6f 73 69 | 74 69 6f 6e 29 2c 20 61 |ld' posi|tion), a| |000010a0| 6e 64 20 51 58 5b 30 5d | 20 77 69 6c 6c 20 67 65 |nd QX[0]| will ge| |000010b0| 74 20 61 20 6e 65 77 20 | 76 61 6c 75 65 2e 20 49 |t a new |value. I| |000010c0| 6e 20 6f 74 68 65 72 20 | 0d 09 2f 2f 20 77 6f 72 |n other |..// wor| |000010d0| 64 73 2c 20 65 76 65 72 | 79 20 73 77 61 72 6d 20 |ds, ever|y swarm | |000010e0| 65 6c 65 6d 65 6e 74 20 | 65 73 73 65 6e 74 69 61 |element |essentia| |000010f0| 6c 6c 79 20 74 72 61 63 | 65 73 20 61 20 63 6f 6e |lly trac|es a con| |00001100| 74 69 6e 75 6f 75 73 20 | 70 61 74 68 0d 09 2f 2f |tinuous |path..//| |00001110| 20 61 63 72 6f 73 73 20 | 74 68 65 20 73 63 72 65 | across |the scre| |00001120| 65 6e 2e 0d 09 0d 09 0d | 09 2f 2f 20 53 6f 6d 65 |en......|.// Some| |00001130| 20 6d 6f 72 65 20 68 61 | 6e 64 79 20 6d 61 63 72 | more ha|ndy macr| |00001140| 6f 27 73 2e 0d 0d 23 64 | 65 66 69 6e 65 20 52 41 |o's...#d|efine RA| |00001150| 4e 44 28 76 29 20 28 52 | 61 6e 67 65 64 52 64 6d |ND(v) (R|angedRdm| |00001160| 28 2d 28 76 29 2f 32 2c | 20 28 76 29 2f 32 29 29 |(-(v)/2,| (v)/2))| |00001170| 09 09 2f 2f 20 52 61 6e | 64 6f 6d 20 69 6e 74 65 |..// Ran|dom inte| |00001180| 67 65 72 20 61 72 6f 75 | 6e 64 20 30 2e 20 20 0d |ger arou|nd 0. .| |00001190| 23 64 65 66 69 6e 65 20 | 61 62 73 28 78 29 20 28 |#define |abs(x) (| |000011a0| 28 28 78 29 20 3e 20 30 | 29 20 3f 20 28 78 29 20 |((x) > 0|) ? (x) | |000011b0| 3a 20 2d 28 78 29 29 09 | 09 09 2f 2f 20 53 74 61 |: -(x)).|..// Sta| |000011c0| 6e 64 61 72 64 20 6d 61 | 63 72 6f 20 66 6f 72 20 |ndard ma|cro for | |000011d0| 27 61 62 73 27 2e 0d 20 | 0d 23 64 65 66 69 6e 65 |'abs'.. |.#define| |000011e0| 20 73 65 74 6d 69 6e 28 | 78 2c 20 6d 69 6e 29 20 | setmin(|x, min) | |000011f0| 69 66 20 28 78 20 3c 20 | 6d 69 6e 29 20 6d 69 6e |if (x < |min) min| |00001200| 20 3d 20 78 3b 09 2f 2f | 20 4b 65 65 70 20 74 72 | = x;.//| Keep tr| |00001210| 61 63 6b 20 6f 66 20 61 | 20 6d 69 6e 69 6d 75 6d |ack of a| minimum| |00001220| 20 76 61 6c 75 65 2e 0d | 23 64 65 66 69 6e 65 20 | value..|#define | |00001230| 73 65 74 6d 61 78 28 78 | 2c 20 6d 61 78 29 20 69 |setmax(x|, max) i| |00001240| 66 20 28 78 20 3e 20 6d | 61 78 29 20 6d 61 78 20 |f (x > m|ax) max | |00001250| 3d 20 78 3b 09 2f 2f 20 | 4b 65 65 70 20 74 72 61 |= x;.// |Keep tra| |00001260| 63 6b 20 6f 66 20 61 20 | 6d 61 78 6d 69 6d 75 6d |ck of a |maxmimum| |00001270| 20 76 61 6c 75 65 2e 0d | 0d 09 2f 2f 20 41 66 74 | value..|..// Aft| |00001280| 65 72 20 44 61 72 6b 27 | 73 20 77 61 79 20 6f 66 |er Dark'|s way of| |00001290| 20 73 68 6f 77 69 6e 67 | 20 61 6e 20 65 72 72 6f | showing| an erro| |000012a0| 72 20 74 6f 20 74 68 65 | 20 75 73 65 72 2e 0d 09 |r to the| user...| |000012b0| 2f 2f 20 27 23 23 27 20 | 69 73 20 61 6e 20 41 4e |// '##' |is an AN| |000012c0| 53 49 2d 69 73 6d 20 6d | 65 61 6e 69 6e 67 20 6d |SI-ism m|eaning m| |000012d0| 65 74 61 2d 63 6f 6e 63 | 61 74 65 6e 61 74 69 6f |eta-conc|atenatio| |000012e0| 6e 2e 0d 23 64 65 66 69 | 6e 65 20 45 72 72 6f 72 |n..#defi|ne Error| |000012f0| 4d 73 67 28 6d 29 20 42 | 6c 6f 63 6b 4d 6f 76 65 |Msg(m) B|lockMove| |00001300| 28 43 74 6f 50 73 74 72 | 28 6d 29 2c 20 70 61 72 |(CtoPstr|(m), par| |00001310| 61 6d 73 2d 3e 65 72 72 | 6f 72 4d 65 73 73 61 67 |ams->err|orMessag| |00001320| 65 2c 20 31 20 2b 20 6d | 23 23 5b 30 5d 29 3b 0d |e, 1 + m|##[0]);.| |00001330| 0d 09 2f 2f 20 49 6e 20 | 6f 72 64 65 72 20 74 6f |..// In |order to| |00001340| 20 61 76 6f 69 64 20 75 | 6e 65 78 70 65 63 74 65 | avoid u|nexpecte| |00001350| 64 20 62 75 74 20 75 6e | 70 6c 65 61 73 61 6e 74 |d but un|pleasant| |00001360| 20 73 75 72 70 72 69 73 | 65 73 2e 2e 2e 0d 23 64 | surpris|es....#d| |00001370| 65 66 69 6e 65 20 53 61 | 66 65 44 69 73 70 6f 73 |efine Sa|feDispos| |00001380| 48 61 6e 64 6c 65 28 68 | 29 20 69 66 20 28 28 48 |Handle(h|) if ((H| |00001390| 61 6e 64 6c 65 29 28 68 | 29 29 20 44 69 73 70 6f |andle)(h|)) Dispo| |000013a0| 73 65 48 61 6e 64 6c 65 | 28 28 48 61 6e 64 6c 65 |seHandle|((Handle| |000013b0| 29 28 68 29 29 0d 0d 09 | 0d 09 2f 2f 20 4c 65 74 |)(h))...|..// Let| |000013c0| 27 73 20 62 65 20 67 6f | 6f 64 20 41 4e 53 49 20 |'s be go|od ANSI | |000013d0| 63 69 74 69 7a 65 6e 73 | 2c 20 61 6e 64 20 64 65 |citizens|, and de| |000013e0| 66 69 6e 65 20 73 6f 6d | 65 20 66 75 6e 63 74 69 |fine som|e functi| |000013f0| 6f 6e 20 70 72 6f 74 6f | 74 79 70 65 73 2e 0d 09 |on proto|types...| |00001400| 2f 2f 20 54 68 65 73 65 | 20 66 75 6e 63 74 69 6f |// These| functio| |00001410| 6e 73 20 77 69 6c 6c 20 | 62 65 20 63 61 6c 6c 65 |ns will |be calle| |00001420| 64 20 66 72 6f 6d 20 74 | 68 65 20 41 66 74 65 72 |d from t|he After| |00001430| 44 61 72 6b 53 68 65 6c | 6c 2e 63 20 63 6f 64 65 |DarkShel|l.c code| |00001440| 2e 20 0d 4f 53 45 72 72 | 20 44 6f 49 6e 69 74 69 |. .OSErr| DoIniti| |00001450| 61 6c 69 7a 65 28 48 61 | 6e 64 6c 65 20 2a 73 74 |alize(Ha|ndle *st| |00001460| 6f 72 61 67 65 2c 20 52 | 67 6e 48 61 6e 64 6c 65 |orage, R|gnHandle| |00001470| 20 62 6c 61 6e 6b 52 67 | 6e 2c 20 47 4d 50 61 72 | blankRg|n, GMPar| |00001480| 61 6d 42 6c 6f 63 6b 50 | 74 72 20 70 61 72 61 6d |amBlockP|tr param| |00001490| 73 29 3b 0d 4f 53 45 72 | 72 20 44 6f 43 6c 6f 73 |s);.OSEr|r DoClos| |000014a0| 65 28 48 61 6e 64 6c 65 | 20 73 74 6f 72 61 67 65 |e(Handle| storage| |000014b0| 2c 20 52 67 6e 48 61 6e | 64 6c 65 20 62 6c 61 6e |, RgnHan|dle blan| |000014c0| 6b 52 67 6e 2c 20 47 4d | 50 61 72 61 6d 42 6c 6f |kRgn, GM|ParamBlo| |000014d0| 63 6b 50 74 72 20 70 61 | 72 61 6d 73 29 3b 0d 4f |ckPtr pa|rams);.O| |000014e0| 53 45 72 72 20 44 6f 42 | 6c 61 6e 6b 28 48 61 6e |SErr DoB|lank(Han| |000014f0| 64 6c 65 20 73 74 6f 72 | 61 67 65 2c 20 52 67 6e |dle stor|age, Rgn| |00001500| 48 61 6e 64 6c 65 20 62 | 6c 61 6e 6b 52 67 6e 2c |Handle b|lankRgn,| |00001510| 20 47 4d 50 61 72 61 6d | 42 6c 6f 63 6b 50 74 72 | GMParam|BlockPtr| |00001520| 20 70 61 72 61 6d 73 29 | 3b 0d 4f 53 45 72 72 20 | params)|;.OSErr | |00001530| 44 6f 44 72 61 77 46 72 | 61 6d 65 28 48 61 6e 64 |DoDrawFr|ame(Hand| |00001540| 6c 65 20 73 74 6f 72 61 | 67 65 2c 20 52 67 6e 48 |le stora|ge, RgnH| |00001550| 61 6e 64 6c 65 20 62 6c | 61 6e 6b 52 67 6e 2c 20 |andle bl|ankRgn, | |00001560| 47 4d 50 61 72 61 6d 42 | 6c 6f 63 6b 50 74 72 20 |GMParamB|lockPtr | |00001570| 70 61 72 61 6d 73 29 3b | 0d 4f 53 45 72 72 20 44 |params);|.OSErr D| |00001580| 6f 48 65 6c 70 28 52 67 | 6e 48 61 6e 64 6c 65 20 |oHelp(Rg|nHandle | |00001590| 62 6c 61 6e 6b 52 67 6e | 2c 20 47 4d 50 61 72 61 |blankRgn|, GMPara| |000015a0| 6d 42 6c 6f 63 6b 50 74 | 72 20 70 61 72 61 6d 73 |mBlockPt|r params| |000015b0| 29 3b 0d 0d 09 2f 2f 20 | 53 6f 6d 65 20 6c 6f 63 |);...// |Some loc| |000015c0| 61 6c 20 66 75 6e 63 74 | 69 6f 6e 73 20 6f 66 20 |al funct|ions of | |000015d0| 6d 79 20 6f 77 6e 2e 0d | 4f 53 45 72 72 09 41 62 |my own..|OSErr.Ab| |000015e0| 6f 75 74 42 6f 78 45 72 | 72 6f 72 28 52 65 63 74 |outBoxEr|ror(Rect| |000015f0| 20 67 72 61 66 29 3b 0d | 69 6e 74 20 20 20 20 20 | graf);.|int | |00001600| 52 61 6e 67 65 64 52 64 | 6d 28 69 6e 74 20 6d 69 |RangedRd|m(int mi| |00001610| 6e 2c 20 69 6e 74 20 6d | 61 78 29 3b 0d 48 61 6e |n, int m|ax);.Han| |00001620| 64 6c 65 09 42 65 73 74 | 4e 65 77 48 61 6e 64 6c |dle.Best|NewHandl| |00001630| 65 28 53 69 7a 65 20 73 | 29 3b 0d 42 6f 6f 6c 65 |e(Size s|);.Boole| |00001640| 61 6e 20 58 59 49 6e 52 | 65 63 74 28 52 65 63 74 |an XYInR|ect(Rect| |00001650| 20 2a 72 2c 20 69 6e 74 | 20 78 2c 20 69 6e 74 20 | *r, int| x, int | |00001660| 79 29 3b 0d 0d 0d 09 2f | 2f 20 4e 6f 77 20 77 65 |y);..../|/ Now we| |00001670| 20 63 6f 6d 65 20 74 68 | 65 20 66 75 6e 20 70 61 | come th|e fun pa| |00001680| 72 74 3a 20 74 68 65 20 | 61 63 74 75 61 6c 20 69 |rt: the |actual i| |00001690| 6d 70 6c 65 6d 65 6e 74 | 61 74 69 6f 6e 73 20 6f |mplement|ations o| |000016a0| 66 20 74 68 65 20 66 75 | 6e 63 74 69 6f 6e 73 2e |f the fu|nctions.| |000016b0| 0d 09 2f 2f 20 46 69 72 | 73 74 3a 20 44 6f 49 6e |..// Fir|st: DoIn| |000016c0| 69 74 69 61 6c 69 7a 65 | 2c 20 77 68 69 63 68 20 |itialize|, which | |000016d0| 61 6c 6c 6f 63 61 74 65 | 73 20 6f 75 72 20 73 77 |allocate|s our sw| |000016e0| 61 72 6d 20 64 61 74 61 | 20 73 74 72 75 63 74 75 |arm data| structu| |000016f0| 72 65 20 61 73 20 64 65 | 66 69 6e 65 64 0d 09 2f |re as de|fined../| |00001700| 2f 20 61 62 6f 76 65 2c | 20 69 6e 69 74 69 61 6c |/ above,| initial| |00001710| 69 7a 65 73 20 74 68 65 | 20 76 61 72 69 61 62 6c |izes the| variabl| |00001720| 65 73 20 69 6e 20 74 68 | 61 74 20 73 74 72 75 63 |es in th|at struc| |00001730| 74 2c 20 61 6e 64 20 64 | 6f 65 73 20 61 20 67 61 |t, and d|oes a ga| |00001740| 7a 69 6c 6c 69 6f 6e 20 | 63 68 65 63 6b 73 0d 09 |zillion |checks..| |00001750| 2f 2f 20 66 6f 72 20 70 | 6f 73 73 69 62 6c 65 20 |// for p|ossible | |00001760| 70 72 6f 62 6c 65 6d 73 | 2e 0d 0d 4f 53 45 72 72 |problems|...OSErr| |00001770| 0d 44 6f 49 6e 69 74 69 | 61 6c 69 7a 65 28 48 61 |.DoIniti|alize(Ha| |00001780| 6e 64 6c 65 20 2a 73 74 | 6f 72 61 67 65 2c 20 52 |ndle *st|orage, R| |00001790| 67 6e 48 61 6e 64 6c 65 | 20 62 6c 61 6e 6b 52 67 |gnHandle| blankRg| |000017a0| 6e 2c 20 47 4d 50 61 72 | 61 6d 42 6c 6f 63 6b 50 |n, GMPar|amBlockP| |000017b0| 74 72 20 70 61 72 61 6d | 73 29 0d 7b 0d 20 20 20 |tr param|s).{. | |000017c0| 20 72 65 67 69 73 74 65 | 72 20 53 77 61 72 6d 53 | registe|r SwarmS| |000017d0| 74 6f 72 61 67 65 50 74 | 72 20 73 77 61 72 6d 3b |toragePt|r swarm;| |000017e0| 09 09 2f 2f 20 54 68 65 | 20 73 77 61 72 6d 2c 20 |..// The| swarm, | |000017f0| 6f 62 76 69 6f 75 73 6c | 79 0d 20 20 20 20 72 65 |obviousl|y. re| |00001800| 67 69 73 74 65 72 20 69 | 6e 74 20 62 3b 09 09 09 |gister i|nt b;...| |00001810| 09 09 09 2f 2f 20 43 6f | 75 6e 74 65 72 20 66 6f |...// Co|unter fo| |00001820| 72 20 42 65 65 20 6c 6f | 6f 70 73 0d 20 20 20 20 |r Bee lo|ops. | |00001830| 20 20 20 20 0d 20 20 20 | 20 20 20 20 20 2f 2f 20 | . | // | |00001840| 4c 6f 63 61 6c 20 76 61 | 72 69 61 62 6c 65 73 20 |Local va|riables | |00001850| 69 6e 20 6f 72 64 65 72 | 20 74 6f 20 61 76 6f 69 |in order| to avoi| |00001860| 64 20 68 61 76 69 6e 67 | 20 74 6f 20 77 72 69 74 |d having| to writ| |00001870| 65 0d 20 20 20 20 20 20 | 20 20 2f 2f 20 27 73 77 |e. | // 'sw| |00001880| 61 72 6d 2d 3e 2e 2e 2e | 27 20 61 6c 6c 20 74 68 |arm->...|' all th| |00001890| 65 20 74 69 6d 65 2e 20 | 43 6f 75 6c 64 20 68 61 |e time. |Could ha| |000018a0| 76 65 20 75 73 65 64 20 | 6d 61 63 72 6f 27 73 20 |ve used |macro's | |000018b0| 68 65 72 65 20 61 73 0d | 20 20 20 20 20 20 20 20 |here as.| | |000018c0| 2f 2f 20 77 65 6c 6c 2c | 20 49 20 73 75 70 70 6f |// well,| I suppo| |000018d0| 73 65 2e 0d 09 52 47 42 | 43 6f 6c 6f 72 20 77 68 |se...RGB|Color wh| |000018e0| 69 74 65 52 47 42 2c 20 | 62 6c 61 63 6b 52 47 42 |iteRGB, |blackRGB| |000018f0| 2c 20 71 75 65 65 6e 52 | 47 42 2c 20 62 65 65 52 |, queenR|GB, beeR| |00001900| 47 42 3b 0d 09 69 6e 74 | 20 6e 42 65 65 73 3b 0d |GB;..int| nBees;.| |00001910| 09 6c 6f 6e 67 20 64 65 | 6c 61 79 3b 0d 09 0d 09 |.long de|lay;....| |00001920| 09 2f 2f 20 49 66 20 41 | 66 74 65 72 20 44 61 72 |.// If A|fter Dar| |00001930| 6b 20 69 73 20 69 6e 20 | 64 65 6d 6f 2d 6d 6f 64 |k is in |demo-mod| |00001940| 65 2c 20 74 68 65 20 64 | 65 6d 6f 52 65 63 74 20 |e, the d|emoRect | |00001950| 63 61 6e 20 62 65 20 66 | 6f 75 6e 64 20 69 6e 20 |can be f|ound in | |00001960| 74 68 65 0d 09 09 2f 2f | 20 70 61 72 61 6d 73 20 |the...//| params | |00001970| 61 72 67 75 6d 65 6e 74 | 20 74 6f 20 74 68 69 73 |argument| to this| |00001980| 20 66 75 6e 63 74 69 6f | 6e 2c 20 62 75 74 20 77 | functio|n, but w| |00001990| 65 20 6e 65 65 64 20 74 | 6f 20 6d 61 6b 65 20 74 |e need t|o make t| |000019a0| 65 6d 70 6f 72 61 72 79 | 0d 09 09 2f 2f 20 63 68 |emporary|...// ch| |000019b0| 61 6e 67 65 73 20 74 6f | 20 69 74 2c 20 73 6f 20 |anges to| it, so | |000019c0| 77 65 20 75 73 65 20 61 | 20 6c 6f 63 61 6c 20 63 |we use a| local c| |000019d0| 6f 70 79 2e 0d 09 52 65 | 63 74 20 62 6f 72 64 65 |opy...Re|ct borde| |000019e0| 72 65 64 44 65 6d 6f 52 | 65 63 74 3b 09 0d 0d 0d |redDemoR|ect;....| |000019f0| 20 20 20 20 20 09 2f 2f | 20 4f 75 72 20 6f 66 66 | .//| Our off| |00001a00| 73 63 72 65 65 6e 20 67 | 72 61 70 68 69 63 73 20 |screen g|raphics | |00001a10| 77 6f 72 6c 64 73 20 6e | 65 65 64 20 43 6f 6c 6f |worlds n|eed Colo| |00001a20| 72 20 51 75 69 63 6b 44 | 72 61 77 2e 0d 09 69 66 |r QuickD|raw...if| |00001a30| 20 28 21 70 61 72 61 6d | 73 2d 3e 63 6f 6c 6f 72 | (!param|s->color| |00001a40| 51 44 41 76 61 69 6c 29 | 0d 09 7b 0d 09 09 44 69 |QDAvail)|..{...Di| |00001a50| 73 70 6f 73 48 61 6e 64 | 6c 65 28 2a 73 74 6f 72 |sposHand|le(*stor| |00001a60| 61 67 65 29 3b 0d 09 09 | 45 72 72 6f 72 4d 73 67 |age);...|ErrorMsg| |00001a70| 28 22 54 68 65 20 53 77 | 61 72 6d 3a 20 20 53 6f |("The Sw|arm: So| |00001a80| 72 72 79 2c 20 49 20 6e | 65 65 64 20 43 6f 6c 6f |rry, I n|eed Colo| |00001a90| 72 20 51 75 69 63 6b 44 | 72 61 77 20 74 6f 20 72 |r QuickD|raw to r| |00001aa0| 75 6e 21 22 29 3b 0d 09 | 09 72 65 74 75 72 6e 20 |un!");..|.return | |00001ab0| 4d 6f 64 75 6c 65 45 72 | 72 6f 72 3b 0d 09 7d 0d |ModuleEr|ror;..}.| |00001ac0| 20 20 20 20 0d 20 20 20 | 20 09 2f 2f 20 41 6c 6c | . | .// All| |00001ad0| 6f 63 61 74 65 20 27 6d | 61 73 74 65 72 27 20 68 |ocate 'm|aster' h| |00001ae0| 61 6e 64 6c 65 20 74 6f | 20 74 68 65 20 73 74 6f |andle to| the sto| |00001af0| 72 61 67 65 20 73 74 72 | 75 63 74 2e 0d 20 20 20 |rage str|uct.. | |00001b00| 20 69 66 20 28 28 2a 73 | 74 6f 72 61 67 65 20 3d | if ((*s|torage =| |00001b10| 20 42 65 73 74 4e 65 77 | 48 61 6e 64 6c 65 28 73 | BestNew|Handle(s| |00001b20| 69 7a 65 6f 66 28 53 77 | 61 72 6d 53 74 6f 72 61 |izeof(Sw|armStora| |00001b30| 67 65 29 29 29 20 3d 3d | 20 4e 55 4c 4c 29 0d 20 |ge))) ==| NULL). | |00001b40| 20 20 20 7b 20 09 0d 20 | 20 20 20 09 45 72 72 6f | { .. | .Erro| |00001b50| 72 4d 73 67 28 22 54 68 | 65 20 53 77 61 72 6d 3a |rMsg("Th|e Swarm:| |00001b60| 20 20 43 6f 75 6c 64 6e | 27 74 20 61 6c 6c 6f 63 | Couldn|'t alloc| |00001b70| 61 74 65 20 65 6e 6f 75 | 67 68 20 6d 65 6d 6f 72 |ate enou|gh memor| |00001b80| 79 21 22 29 3b 0d 20 20 | 20 20 09 72 65 74 75 72 |y!");. | .retur| |00001b90| 6e 20 4d 6f 64 75 6c 65 | 45 72 72 6f 72 3b 0d 20 |n Module|Error;. | |00001ba0| 20 20 20 7d 0d 0d 20 20 | 20 20 09 2f 2f 20 4c 6f | }.. | .// Lo| |00001bb0| 63 6b 20 64 6f 77 6e 20 | 74 68 65 20 73 74 6f 72 |ck down |the stor| |00001bc0| 61 67 65 20 73 6f 20 77 | 65 20 63 61 6e 20 72 65 |age so w|e can re| |00001bd0| 66 65 72 20 74 6f 20 69 | 74 20 62 79 20 70 6f 69 |fer to i|t by poi| |00001be0| 6e 74 65 72 2e 20 0d 20 | 20 20 20 48 4c 6f 63 6b |nter. . | HLock| |00001bf0| 48 69 28 2a 73 74 6f 72 | 61 67 65 29 3b 0d 20 20 |Hi(*stor|age);. | |00001c00| 20 20 73 77 61 72 6d 20 | 3d 20 28 53 77 61 72 6d | swarm |= (Swarm| |00001c10| 53 74 6f 72 61 67 65 50 | 74 72 29 20 2a 2a 73 74 |StorageP|tr) **st| |00001c20| 6f 72 61 67 65 3b 0d 20 | 20 20 20 20 20 20 20 0d |orage;. | .| |00001c30| 20 20 20 20 20 20 20 20 | 0d 09 09 2f 2f 20 53 65 | |...// Se| |00001c40| 74 20 75 70 20 61 6e 64 | 20 69 6e 69 74 69 61 6c |t up and| initial| |00001c50| 69 7a 65 20 74 68 65 20 | 63 6f 6c 6f 72 73 20 77 |ize the |colors w| |00001c60| 65 20 75 73 65 2e 0d 09 | 09 09 09 09 0d 09 09 2f |e use...|......./| |00001c70| 2f 20 41 62 73 6f 6c 75 | 74 65 20 62 6c 61 63 6b |/ Absolu|te black| |00001c80| 20 61 6e 64 20 77 68 69 | 74 65 2e 0d 09 77 68 69 | and whi|te...whi| |00001c90| 74 65 52 47 42 2e 72 65 | 64 20 3d 20 77 68 69 74 |teRGB.re|d = whit| |00001ca0| 65 52 47 42 2e 67 72 65 | 65 6e 20 3d 20 77 68 69 |eRGB.gre|en = whi| |00001cb0| 74 65 52 47 42 2e 62 6c | 75 65 20 3d 20 30 78 46 |teRGB.bl|ue = 0xF| |00001cc0| 46 46 46 3b 0d 09 62 6c | 61 63 6b 52 47 42 2e 72 |FFF;..bl|ackRGB.r| |00001cd0| 65 64 20 3d 20 62 6c 61 | 63 6b 52 47 42 2e 67 72 |ed = bla|ckRGB.gr| |00001ce0| 65 65 6e 20 3d 20 62 6c | 61 63 6b 52 47 42 2e 62 |een = bl|ackRGB.b| |00001cf0| 6c 75 65 20 3d 20 30 3b | 0d 09 0d 09 09 2f 2f 20 |lue = 0;|.....// | |00001d00| 41 20 67 6f 6c 64 65 6e | 20 63 6f 6c 6f 72 20 66 |A golden| color f| |00001d10| 6f 72 20 74 68 65 20 42 | 65 65 73 2c 20 61 20 62 |or the B|ees, a b| |00001d20| 72 69 67 68 74 20 72 65 | 64 20 66 6f 72 20 74 68 |right re|d for th| |00001d30| 65 20 51 75 65 65 6e 2e | 0d 09 62 65 65 52 47 42 |e Queen.|..beeRGB| |00001d40| 2e 72 65 64 20 3d 20 30 | 78 46 46 46 46 3b 20 62 |.red = 0|xFFFF; b| |00001d50| 65 65 52 47 42 2e 67 72 | 65 65 6e 20 3d 20 30 78 |eeRGB.gr|een = 0x| |00001d60| 39 43 39 43 3b 20 62 65 | 65 52 47 42 2e 62 6c 75 |9C9C; be|eRGB.blu| |00001d70| 65 20 3d 20 30 78 30 38 | 30 38 3b 0d 09 71 75 65 |e = 0x08|08;..que| |00001d80| 65 6e 52 47 42 2e 72 65 | 64 20 3d 20 30 78 42 44 |enRGB.re|d = 0xBD| |00001d90| 42 44 3b 20 71 75 65 65 | 6e 52 47 42 2e 67 72 65 |BD; quee|nRGB.gre| |00001da0| 65 6e 20 3d 20 30 3b 20 | 71 75 65 65 6e 52 47 42 |en = 0; |queenRGB| |00001db0| 2e 62 6c 75 65 20 3d 20 | 30 3b 0d 09 0d 09 09 2f |.blue = |0;...../| |00001dc0| 2f 20 54 68 65 20 51 75 | 65 65 6e 27 73 20 72 65 |/ The Qu|een's re| |00001dd0| 64 20 63 6f 6c 6f 72 20 | 67 65 74 73 20 6d 61 70 |d color |gets map| |00001de0| 70 65 64 20 74 6f 20 62 | 6c 61 63 6b 20 62 79 20 |ped to b|lack by | |00001df0| 74 68 65 20 4d 61 63 0d | 09 09 2f 2f 20 69 66 20 |the Mac.|..// if | |00001e00| 74 68 65 20 73 63 72 65 | 65 6e 20 69 73 20 6c 65 |the scre|en is le| |00001e10| 73 73 20 74 68 65 6e 20 | 38 2d 62 69 74 2e 20 57 |ss then |8-bit. W| |00001e20| 65 20 64 6f 6e 27 74 20 | 77 61 6e 74 20 74 68 61 |e don't |want tha| |00001e30| 74 2e 2e 2e 0d 09 69 66 | 20 28 70 61 72 61 6d 73 |t.....if| (params| |00001e40| 2d 3e 6d 6f 6e 69 74 6f | 72 73 2d 3e 6d 6f 6e 69 |->monito|rs->moni| |00001e50| 74 6f 72 4c 69 73 74 5b | 30 5d 2e 63 75 72 44 65 |torList[|0].curDe| |00001e60| 70 74 68 20 3c 20 34 29 | 0d 09 09 71 75 65 65 6e |pth < 4)|...queen| |00001e70| 52 47 42 20 3d 20 77 68 | 69 74 65 52 47 42 3b 0d |RGB = wh|iteRGB;.| |00001e80| 0d 09 09 2f 2f 20 54 68 | 69 73 20 69 73 20 61 20 |...// Th|is is a | |00001e90| 76 65 72 79 20 63 72 75 | 64 65 20 61 6e 64 20 73 |very cru|de and s| |00001ea0| 74 75 70 69 64 20 77 61 | 79 20 74 6f 20 74 72 79 |tupid wa|y to try| |00001eb0| 20 61 6e 64 20 64 65 74 | 65 63 74 20 69 66 20 74 | and det|ect if t| |00001ec0| 68 65 20 6d 61 69 6e 20 | 73 63 72 65 65 6e 0d 09 |he main |screen..| |00001ed0| 09 2f 2f 20 69 73 20 69 | 6e 20 67 72 61 79 73 63 |.// is i|n graysc| |00001ee0| 61 6c 65 20 6d 6f 64 65 | 2e 20 49 66 20 73 6f 2c |ale mode|. If so,| |00001ef0| 20 49 20 6d 61 6b 65 20 | 74 68 65 20 65 6e 74 69 | I make |the enti| |00001f00| 72 65 20 61 6e 69 6d 61 | 74 69 6f 6e 20 77 68 69 |re anima|tion whi| |00001f10| 74 65 2d 6f 6e 2d 62 6c | 61 63 6b 2c 0d 09 09 2f |te-on-bl|ack,.../| |00001f20| 2f 20 73 69 6e 63 65 20 | 61 6e 79 74 68 69 6e 67 |/ since |anything| |00001f30| 20 65 6c 73 65 20 69 73 | 20 67 75 61 72 61 6e 74 | else is| guarant| |00001f40| 65 65 64 20 74 6f 20 6d | 61 6b 65 20 65 69 74 68 |eed to m|ake eith| |00001f50| 65 72 20 74 68 65 20 71 | 75 65 65 6e 20 6f 72 20 |er the q|ueen or | |00001f60| 74 68 65 20 64 72 6f 6e | 65 73 0d 09 09 2f 2f 20 |the dron|es...// | |00001f70| 6c 6f 6f 6b 20 74 6f 20 | 64 61 72 6b 2c 20 65 76 |look to |dark, ev| |00001f80| 65 6e 20 75 6e 64 65 72 | 20 32 35 36 20 67 72 61 |en under| 256 gra| |00001f90| 79 73 68 61 64 65 73 2e | 0d 09 09 2f 2f 20 49 6e |yshades.|...// In| |00001fa0| 20 74 68 65 20 6e 65 78 | 74 20 76 65 72 73 69 6f | the nex|t versio| |00001fb0| 6e 2c 20 74 68 69 73 20 | 77 69 6c 6c 20 61 6c 6c |n, this |will all| |00001fc0| 20 62 65 20 73 6f 6c 76 | 65 64 20 6d 75 63 68 20 | be solv|ed much | |00001fd0| 63 6c 65 61 6e 65 72 2c | 20 74 6f 67 65 74 68 65 |cleaner,| togethe| |00001fe0| 72 0d 09 09 2f 2f 20 77 | 69 74 68 20 74 68 65 20 |r...// w|ith the | |00001ff0| 63 75 72 72 65 6e 74 6c | 79 20 75 6e 73 75 70 70 |currentl|y unsupp| |00002000| 6f 72 74 65 64 20 63 61 | 73 65 20 6f 66 20 6d 75 |orted ca|se of mu| |00002010| 6c 74 69 70 6c 65 2d 6d | 6f 6e 69 74 6f 72 20 73 |ltiple-m|onitor s| |00002020| 65 74 75 70 73 2e 0d 09 | 69 66 20 28 21 28 70 61 |etups...|if (!(pa| |00002030| 72 61 6d 73 2d 3e 73 79 | 73 74 65 6d 43 6f 6e 66 |rams->sy|stemConf| |00002040| 69 67 20 26 20 28 31 4c | 20 3c 3c 20 33 29 29 29 |ig & (1L| << 3)))| |00002050| 0d 09 7b 0d 09 09 62 65 | 65 52 47 42 20 3d 20 71 |..{...be|eRGB = q| |00002060| 75 65 65 6e 52 47 42 20 | 3d 20 77 68 69 74 65 52 |ueenRGB |= whiteR| |00002070| 47 42 3b 0d 09 7d 0d 09 | 0d 09 73 77 61 72 6d 2d |GB;..}..|..swarm-| |00002080| 3e 77 68 69 74 65 52 47 | 42 20 3d 20 77 68 69 74 |>whiteRG|B = whit| |00002090| 65 52 47 42 3b 0d 09 73 | 77 61 72 6d 2d 3e 62 6c |eRGB;..s|warm->bl| |000020a0| 61 63 6b 52 47 42 20 3d | 20 62 6c 61 63 6b 52 47 |ackRGB =| blackRG| |000020b0| 42 3b 0d 09 73 77 61 72 | 6d 2d 3e 71 75 65 65 6e |B;..swar|m->queen| |000020c0| 52 47 42 20 3d 20 71 75 | 65 65 6e 52 47 42 3b 0d |RGB = qu|eenRGB;.| |000020d0| 09 73 77 61 72 6d 2d 3e | 62 65 65 52 47 42 20 20 |.swarm->|beeRGB | |000020e0| 20 3d 20 62 65 65 52 47 | 42 3b 0d 09 73 77 61 72 | = beeRG|B;..swar| |000020f0| 6d 2d 3e 62 61 63 6b 52 | 47 42 20 20 3d 20 62 6c |m->backR|GB = bl| |00002100| 61 63 6b 52 47 42 3b 0d | 09 0d 09 09 2f 2f 20 57 |ackRGB;.|....// W| |00002110| 65 20 67 65 74 20 6f 75 | 72 20 6e 75 6d 62 65 72 |e get ou|r number| |00002120| 20 6f 66 20 62 65 65 73 | 20 66 72 6f 6d 20 61 20 | of bees| from a | |00002130| 73 6c 69 64 65 20 63 6f | 6e 74 72 6f 6c 20 69 6e |slide co|ntrol in| |00002140| 20 74 68 65 0d 09 09 2f | 2f 20 41 66 74 65 72 20 | the.../|/ After | |00002150| 44 61 72 6b 20 63 6f 6e | 74 72 6f 6c 20 70 61 6e |Dark con|trol pan| |00002160| 65 6c 20 69 6e 74 65 72 | 66 61 63 65 2e 20 54 68 |el inter|face. Th| |00002170| 69 73 20 6e 75 6d 62 65 | 72 20 63 61 6e 20 62 65 |is numbe|r can be| |00002180| 20 7a 65 72 6f 21 0d 09 | 73 77 61 72 6d 2d 3e 6e | zero!..|swarm->n| |00002190| 42 65 65 73 20 3d 20 6e | 42 65 65 73 20 3d 20 70 |Bees = n|Bees = p| |000021a0| 61 72 61 6d 73 2d 3e 63 | 6f 6e 74 72 6f 6c 56 61 |arams->c|ontrolVa| |000021b0| 6c 75 65 73 5b 30 5d 3b | 0d 09 0d 09 09 2f 2f 20 |lues[0];|.....// | |000021c0| 57 65 20 67 65 74 20 74 | 68 65 20 61 6e 69 6d 61 |We get t|he anima| |000021d0| 74 69 6f 6e 20 73 70 65 | 65 64 20 66 72 6f 6d 20 |tion spe|ed from | |000021e0| 61 20 73 65 63 6f 6e 64 | 20 73 6c 69 64 65 20 63 |a second| slide c| |000021f0| 6f 6e 74 72 6f 6c 2e 0d | 09 09 2f 2f 20 54 68 69 |ontrol..|..// Thi| |00002200| 73 20 69 73 20 70 72 69 | 6d 61 72 69 6c 79 20 69 |s is pri|marily i| |00002210| 6e 74 65 6e 64 65 64 20 | 66 6f 72 20 4d 61 63 73 |ntended |for Macs| |00002220| 20 77 68 69 63 68 20 61 | 72 65 20 2a 74 6f 6f 20 | which a|re *too | |00002230| 66 61 73 74 2a 2c 0d 09 | 09 2f 2f 20 77 68 69 63 |fast*,..|.// whic| |00002240| 68 20 69 73 20 77 68 79 | 20 77 65 20 65 78 70 72 |h is why| we expr| |00002250| 65 73 73 20 73 70 65 65 | 64 20 69 6e 20 74 65 72 |ess spee|d in ter| |00002260| 6d 73 20 6f 66 20 74 68 | 65 20 64 65 6c 61 79 20 |ms of th|e delay | |00002270| 62 65 74 77 65 65 6e 20 | 66 72 61 6d 65 73 2e 0d |between |frames..| |00002280| 09 09 2f 2f 20 54 68 69 | 73 20 64 65 6c 61 79 20 |..// Thi|s delay | |00002290| 77 69 6c 6c 20 62 65 20 | 65 69 74 68 65 72 20 30 |will be |either 0| |000022a0| 2c 20 32 2c 20 34 2c 20 | 36 2c 20 38 20 6f 72 20 |, 2, 4, |6, 8 or | |000022b0| 31 30 20 73 79 73 74 65 | 6d 20 74 69 63 6b 73 20 |10 syste|m ticks | |000022c0| 6c 6f 6e 67 2e 0d 09 73 | 77 61 72 6d 2d 3e 64 65 |long...s|warm->de| |000022d0| 6c 61 79 20 3d 20 64 65 | 6c 61 79 20 3d 20 28 6c |lay = de|lay = (l| |000022e0| 6f 6e 67 29 31 30 20 2d | 20 28 32 2a 70 61 72 61 |ong)10 -| (2*para| |000022f0| 6d 73 2d 3e 63 6f 6e 74 | 72 6f 6c 56 61 6c 75 65 |ms->cont|rolValue| |00002300| 73 5b 31 5d 20 2f 20 32 | 30 29 3b 0d 09 0d 09 09 |s[1] / 2|0);.....| |00002310| 2f 2f 20 53 61 6e 69 74 | 79 20 63 68 65 63 6b 73 |// Sanit|y checks| |00002320| 2e 20 54 68 65 73 65 20 | 74 68 69 6e 67 73 20 73 |. These |things s| |00002330| 68 6f 75 6c 64 20 6e 65 | 76 65 72 20 6f 63 63 75 |hould ne|ver occu| |00002340| 72 2e 0d 09 69 66 20 28 | 6e 42 65 65 73 20 3c 20 |r...if (|nBees < | |00002350| 30 20 7c 7c 20 6e 42 65 | 65 73 20 3e 20 31 30 30 |0 || nBe|es > 100| |00002360| 29 0d 09 7b 0d 09 09 44 | 6f 43 6c 6f 73 65 28 2a |)..{...D|oClose(*| |00002370| 73 74 6f 72 61 67 65 2c | 20 28 52 67 6e 48 61 6e |storage,| (RgnHan| |00002380| 64 6c 65 29 20 6e 69 6c | 2c 20 28 47 4d 50 61 72 |dle) nil|, (GMPar| |00002390| 61 6d 42 6c 6f 63 6b 50 | 74 72 29 20 6e 69 6c 29 |amBlockP|tr) nil)| |000023a0| 3b 0d 09 09 45 72 72 6f | 72 4d 73 67 28 22 54 68 |;...Erro|rMsg("Th| |000023b0| 65 20 53 77 61 72 6d 3a | 20 20 49 6e 74 65 72 6e |e Swarm:| Intern| |000023c0| 61 6c 20 45 72 72 6f 72 | 20 d1 20 69 6e 73 61 6e |al Error| . insan| |000023d0| 65 20 6e 75 6d 62 65 72 | 20 6f 66 20 62 65 65 73 |e number| of bees| |000023e0| 21 22 29 3b 0d 09 09 72 | 65 74 75 72 6e 20 4d 6f |!");...r|eturn Mo| |000023f0| 64 75 6c 65 45 72 72 6f | 72 3b 0d 09 7d 0d 09 0d |duleErro|r;..}...| |00002400| 09 69 66 20 28 64 65 6c | 61 79 20 3c 20 30 20 7c |.if (del|ay < 0 || |00002410| 7c 20 64 65 6c 61 79 20 | 3e 20 31 30 29 0d 09 7b || delay |> 10)..{| |00002420| 0d 09 09 44 6f 43 6c 6f | 73 65 28 2a 73 74 6f 72 |...DoClo|se(*stor| |00002430| 61 67 65 2c 20 28 52 67 | 6e 48 61 6e 64 6c 65 29 |age, (Rg|nHandle)| |00002440| 20 6e 69 6c 2c 20 28 47 | 4d 50 61 72 61 6d 42 6c | nil, (G|MParamBl| |00002450| 6f 63 6b 50 74 72 29 20 | 6e 69 6c 29 3b 0d 09 09 |ockPtr) |nil);...| |00002460| 45 72 72 6f 72 4d 73 67 | 28 22 54 68 65 20 53 77 |ErrorMsg|("The Sw| |00002470| 61 72 6d 3a 20 20 49 6e | 74 65 72 6e 61 6c 20 45 |arm: In|ternal E| |00002480| 72 72 6f 72 20 d1 20 69 | 6e 73 61 6e 65 20 62 65 |rror . i|nsane be| |00002490| 65 20 73 70 65 65 64 20 | 76 61 6c 75 65 21 22 29 |e speed |value!")| |000024a0| 3b 0d 09 09 72 65 74 75 | 72 6e 20 4d 6f 64 75 6c |;...retu|rn Modul| |000024b0| 65 45 72 72 6f 72 3b 0d | 09 7d 0d 09 0d 09 09 2f |eError;.|.}...../| |000024c0| 2f 20 53 65 65 20 44 6f | 44 72 61 77 46 72 61 6d |/ See Do|DrawFram| |000024d0| 65 20 66 6f 72 20 6d 6f | 72 65 20 69 6e 66 6f 20 |e for mo|re info | |000024e0| 6f 6e 20 68 6f 77 20 74 | 68 69 73 20 76 61 72 69 |on how t|his vari| |000024f0| 61 62 6c 65 20 69 73 20 | 75 73 65 64 20 74 6f 20 |able is |used to | |00002500| 69 6d 70 6c 65 6d 65 6e | 74 0d 09 09 2f 2f 20 74 |implemen|t...// t| |00002510| 68 65 20 64 65 6c 61 79 | 2e 0d 09 73 77 61 72 6d |he delay|...swarm| |00002520| 2d 3e 73 74 61 72 74 44 | 72 61 77 69 6e 67 20 3d |->startD|rawing =| |00002530| 20 54 69 63 6b 73 3b 0d | 0d 09 09 2f 2f 20 57 65 | Ticks;.|...// We| |00002540| 20 6e 65 65 64 20 74 6f | 20 6b 6e 6f 77 20 69 66 | need to| know if| |00002550| 20 77 65 20 61 72 65 20 | 69 6e 20 64 65 6d 6f 20 | we are |in demo | |00002560| 4d 6f 64 65 20 69 6e 20 | 74 68 65 20 44 6f 44 72 |Mode in |the DoDr| |00002570| 61 77 46 72 61 6d 65 20 | 66 75 6e 63 74 69 6f 6e |awFrame |function| |00002580| 2c 0d 09 09 2f 2f 20 62 | 75 74 20 77 65 20 77 61 |,...// b|ut we wa| |00002590| 6e 74 20 74 6f 20 61 76 | 6f 69 64 20 68 61 76 69 |nt to av|oid havi| |000025a0| 6e 67 20 74 6f 20 63 61 | 6c 6c 20 74 68 65 20 45 |ng to ca|ll the E| |000025b0| 6d 70 74 79 52 65 63 74 | 20 66 75 6e 63 74 69 6f |mptyRect| functio| |000025c0| 6e 20 65 76 65 72 79 20 | 74 69 6d 65 2c 0d 09 09 |n every |time,...| |000025d0| 2f 2f 20 73 6f 20 77 65 | 20 73 74 6f 72 65 20 69 |// so we| store i| |000025e0| 74 20 69 6e 20 61 20 42 | 6f 6f 6c 65 61 6e 20 68 |t in a B|oolean h| |000025f0| 65 72 65 2e 0d 09 73 77 | 61 72 6d 2d 3e 64 65 6d |ere...sw|arm->dem| |00002600| 6f 4d 6f 64 65 20 3d 20 | 21 45 6d 70 74 79 52 65 |oMode = |!EmptyRe| |00002610| 63 74 28 28 26 70 61 72 | 61 6d 73 2d 3e 64 65 6d |ct((&par|ams->dem| |00002620| 6f 52 65 63 74 29 29 3b | 0d 09 09 0d 09 09 2f 2f |oRect));|......//| |00002630| 20 41 6c 6c 6f 63 61 74 | 65 20 68 61 6e 64 6c 65 | Allocat|e handle| |00002640| 73 2c 20 61 6e 64 20 61 | 66 74 65 72 77 61 72 64 |s, and a|fterward| |00002650| 73 20 28 61 29 20 63 68 | 65 63 6b 20 69 66 20 74 |s (a) ch|eck if t| |00002660| 68 65 20 61 6c 6c 6f 63 | 61 74 69 6f 6e 0d 09 09 |he alloc|ation...| |00002670| 2f 2f 20 73 75 63 63 65 | 65 64 65 64 2c 20 61 6e |// succe|eded, an| |00002680| 64 20 28 62 29 20 6d 6f | 76 65 20 74 68 65 20 68 |d (b) mo|ve the h| |00002690| 61 6e 64 6c 65 73 20 74 | 6f 20 68 69 67 68 20 6d |andles t|o high m| |000026a0| 65 6d 6f 72 79 20 61 6e | 64 20 6c 6f 63 6b 20 74 |emory an|d lock t| |000026b0| 68 65 6d 2e 0d 09 09 2f | 2f 20 49 20 63 6f 75 6c |hem..../|/ I coul| |000026c0| 64 20 68 61 76 65 20 64 | 6f 6e 65 20 74 68 69 73 |d have d|one this| |000026d0| 20 77 69 74 68 20 73 74 | 61 74 69 63 20 61 72 72 | with st|atic arr| |000026e0| 61 79 73 20 28 62 65 65 | 58 5b 32 5d 5b 4d 41 58 |ays (bee|X[2][MAX| |000026f0| 42 45 45 53 5d 29 2c 0d | 09 09 2f 2f 20 49 20 73 |BEES]),.|..// I s| |00002700| 75 70 70 6f 73 65 2c 20 | 62 75 74 20 49 20 77 61 |uppose, |but I wa| |00002710| 6e 74 65 64 20 74 6f 20 | 6c 65 61 72 6e 20 68 6f |nted to |learn ho| |00002720| 77 20 74 6f 20 77 6f 72 | 6b 20 77 69 74 68 20 68 |w to wor|k with h| |00002730| 61 6e 64 6c 65 73 2e 0d | 09 09 2f 2f 20 54 68 65 |andles..|..// The| |00002740| 20 73 70 65 65 64 20 64 | 69 66 66 65 72 65 6e 63 | speed d|ifferenc| |00002750| 65 20 69 6e 20 61 63 63 | 65 73 73 20 69 73 2c 20 |e in acc|ess is, | |00002760| 74 6f 20 6d 79 20 73 75 | 72 70 72 69 73 65 2c 20 |to my su|rprise, | |00002770| 6e 65 67 6c 69 67 69 62 | 6c 65 2c 0d 09 09 2f 2f |negligib|le,...//| |00002780| 20 53 6f 20 49 20 73 65 | 65 20 6e 6f 20 72 65 61 | So I se|e no rea| |00002790| 73 6f 6e 20 74 6f 20 63 | 68 61 6e 67 65 20 69 74 |son to c|hange it| |000027a0| 20 62 61 63 6b 2e 0d 09 | 09 2f 2f 0d 09 09 2f 2f | back...|.//...//| |000027b0| 20 4e 6f 74 69 63 65 20 | 74 68 61 74 20 77 65 20 | Notice |that we | |000027c0| 61 6c 6c 6f 63 61 74 65 | 20 65 6e 6f 75 67 68 20 |allocate| enough | |000027d0| 6d 65 6d 6f 72 79 20 66 | 6f 72 20 74 68 65 20 6d |memory f|or the m| |000027e0| 61 78 69 6d 75 6d 20 6e | 75 6d 62 65 72 0d 09 09 |aximum n|umber...| |000027f0| 2f 2f 20 6f 66 20 42 65 | 65 73 20 69 6e 20 61 64 |// of Be|es in ad| |00002800| 76 61 6e 63 65 2e 20 54 | 68 69 73 20 69 73 20 62 |vance. T|his is b| |00002810| 65 63 61 75 73 65 20 69 | 6e 20 44 65 6d 6f 20 4d |ecause i|n Demo M| |00002820| 6f 64 65 20 77 65 20 77 | 61 6e 74 20 74 6f 0d 09 |ode we w|ant to..| |00002830| 09 2f 2f 20 62 65 20 61 | 62 6c 65 20 74 6f 20 6c |.// be a|ble to l| |00002840| 65 74 20 74 68 65 20 75 | 73 65 72 20 64 79 6e 61 |et the u|ser dyna| |00002850| 6d 69 63 61 6c 6c 79 20 | 63 68 61 6e 67 65 20 6e |mically |change n| |00002860| 42 65 65 73 2c 20 77 68 | 69 63 68 20 69 73 0d 09 |Bees, wh|ich is..| |00002870| 09 2f 2f 20 74 68 65 20 | 2a 63 75 72 72 65 6e 74 |.// the |*current| |00002880| 2a 20 6e 75 6d 62 65 72 | 20 6f 66 20 42 65 65 73 |* number| of Bees| |00002890| 2c 20 69 66 20 79 6f 75 | 27 6c 6c 20 72 65 6d 65 |, if you|'ll reme| |000028a0| 6d 62 65 72 2e 20 49 6e | 20 6f 72 64 65 72 20 74 |mber. In| order t| |000028b0| 6f 0d 09 09 2f 2f 20 64 | 6f 20 74 68 61 74 20 6e |o...// d|o that n| |000028c0| 65 61 74 6c 79 2c 20 77 | 65 20 77 61 6e 74 20 74 |eatly, w|e want t| |000028d0| 6f 20 68 61 76 65 20 74 | 68 65 20 73 74 6f 72 61 |o have t|he stora| |000028e0| 67 65 20 72 65 61 64 79 | 20 61 6e 64 20 69 6e 69 |ge ready| and ini| |000028f0| 74 69 61 6c 69 7a 65 64 | 0d 09 09 2f 2f 20 62 65 |tialized|...// be| |00002900| 66 6f 72 65 68 61 6e 64 | 2e 0d 09 09 0d 09 73 77 |forehand|......sw| |00002910| 61 72 6d 2d 3e 62 65 65 | 58 5b 30 5d 20 3d 20 28 |arm->bee|X[0] = (| |00002920| 49 6e 74 48 61 6e 64 6c | 65 29 20 42 65 73 74 4e |IntHandl|e) BestN| |00002930| 65 77 48 61 6e 64 6c 65 | 28 4d 41 58 42 45 45 53 |ewHandle|(MAXBEES| |00002940| 2a 73 69 7a 65 6f 66 28 | 69 6e 74 29 29 3b 0d 09 |*sizeof(|int));..| |00002950| 73 77 61 72 6d 2d 3e 62 | 65 65 58 5b 31 5d 20 3d |swarm->b|eeX[1] =| |00002960| 20 28 49 6e 74 48 61 6e | 64 6c 65 29 20 42 65 73 | (IntHan|dle) Bes| |00002970| 74 4e 65 77 48 61 6e 64 | 6c 65 28 4d 41 58 42 45 |tNewHand|le(MAXBE| |00002980| 45 53 2a 73 69 7a 65 6f | 66 28 69 6e 74 29 29 3b |ES*sizeo|f(int));| |00002990| 0d 09 73 77 61 72 6d 2d | 3e 62 65 65 59 5b 30 5d |..swarm-|>beeY[0]| |000029a0| 20 3d 20 28 49 6e 74 48 | 61 6e 64 6c 65 29 20 42 | = (IntH|andle) B| |000029b0| 65 73 74 4e 65 77 48 61 | 6e 64 6c 65 28 4d 41 58 |estNewHa|ndle(MAX| |000029c0| 42 45 45 53 2a 73 69 7a | 65 6f 66 28 69 6e 74 29 |BEES*siz|eof(int)| |000029d0| 29 3b 0d 09 73 77 61 72 | 6d 2d 3e 62 65 65 59 5b |);..swar|m->beeY[| |000029e0| 31 5d 20 3d 20 28 49 6e | 74 48 61 6e 64 6c 65 29 |1] = (In|tHandle)| |000029f0| 20 42 65 73 74 4e 65 77 | 48 61 6e 64 6c 65 28 4d | BestNew|Handle(M| |00002a00| 41 58 42 45 45 53 2a 73 | 69 7a 65 6f 66 28 69 6e |AXBEES*s|izeof(in| |00002a10| 74 29 29 3b 0d 0d 09 73 | 77 61 72 6d 2d 3e 62 65 |t));...s|warm->be| |00002a20| 65 56 65 6c 58 20 3d 20 | 28 49 6e 74 48 61 6e 64 |eVelX = |(IntHand| |00002a30| 6c 65 29 20 42 65 73 74 | 4e 65 77 48 61 6e 64 6c |le) Best|NewHandl| |00002a40| 65 28 4d 41 58 42 45 45 | 53 2a 73 69 7a 65 6f 66 |e(MAXBEE|S*sizeof| |00002a50| 28 69 6e 74 29 29 3b 0d | 09 73 77 61 72 6d 2d 3e |(int));.|.swarm->| |00002a60| 62 65 65 56 65 6c 59 20 | 3d 20 28 49 6e 74 48 61 |beeVelY |= (IntHa| |00002a70| 6e 64 6c 65 29 20 42 65 | 73 74 4e 65 77 48 61 6e |ndle) Be|stNewHan| |00002a80| 64 6c 65 28 4d 41 58 42 | 45 45 53 2a 73 69 7a 65 |dle(MAXB|EES*size| |00002a90| 6f 66 28 69 6e 74 29 29 | 3b 0d 09 0d 09 69 66 20 |of(int))|;....if | |00002aa0| 28 21 28 73 77 61 72 6d | 2d 3e 62 65 65 58 5b 30 |(!(swarm|->beeX[0| |00002ab0| 5d 20 26 26 20 73 77 61 | 72 6d 2d 3e 62 65 65 58 |] && swa|rm->beeX| |00002ac0| 5b 31 5d 20 26 26 20 73 | 77 61 72 6d 2d 3e 62 65 |[1] && s|warm->be| |00002ad0| 65 59 5b 30 5d 20 26 26 | 20 73 77 61 72 6d 2d 3e |eY[0] &&| swarm->| |00002ae0| 62 65 65 59 5b 31 5d 0d | 09 09 20 20 26 26 20 73 |beeY[1].|.. && s| |00002af0| 77 61 72 6d 2d 3e 62 65 | 65 56 65 6c 58 20 26 26 |warm->be|eVelX &&| |00002b00| 20 73 77 61 72 6d 2d 3e | 62 65 65 56 65 6c 59 29 | swarm->|beeVelY)| |00002b10| 29 0d 09 7b 0d 09 09 44 | 6f 43 6c 6f 73 65 28 2a |)..{...D|oClose(*| |00002b20| 73 74 6f 72 61 67 65 2c | 20 28 52 67 6e 48 61 6e |storage,| (RgnHan| |00002b30| 64 6c 65 29 20 6e 69 6c | 2c 20 28 47 4d 50 61 72 |dle) nil|, (GMPar| |00002b40| 61 6d 42 6c 6f 63 6b 50 | 74 72 29 20 6e 69 6c 29 |amBlockP|tr) nil)| |00002b50| 3b 0d 09 09 45 72 72 6f | 72 4d 73 67 28 22 54 68 |;...Erro|rMsg("Th| |00002b60| 65 20 53 77 61 72 6d 3a | 20 20 43 6f 75 6c 64 6e |e Swarm:| Couldn| |00002b70| 27 74 20 61 6c 6c 6f 63 | 61 74 65 20 65 6e 6f 75 |'t alloc|ate enou| |00002b80| 67 68 20 69 6e 74 65 72 | 6e 61 6c 20 6d 65 6d 6f |gh inter|nal memo| |00002b90| 72 79 21 22 29 3b 0d 09 | 09 72 65 74 75 72 6e 20 |ry!");..|.return | |00002ba0| 4d 6f 64 75 6c 65 45 72 | 72 6f 72 3b 0d 09 7d 0d |ModuleEr|ror;..}.| |00002bb0| 09 0d 09 48 4c 6f 63 6b | 48 69 28 28 48 61 6e 64 |...HLock|Hi((Hand| |00002bc0| 6c 65 29 20 73 77 61 72 | 6d 2d 3e 62 65 65 58 5b |le) swar|m->beeX[| |00002bd0| 30 5d 29 3b 0d 20 20 20 | 20 48 4c 6f 63 6b 48 69 |0]);. | HLockHi| |00002be0| 28 28 48 61 6e 64 6c 65 | 29 20 73 77 61 72 6d 2d |((Handle|) swarm-| |00002bf0| 3e 62 65 65 58 5b 31 5d | 29 3b 0d 20 20 20 20 48 |>beeX[1]|);. H| |00002c00| 4c 6f 63 6b 48 69 28 28 | 48 61 6e 64 6c 65 29 20 |LockHi((|Handle) | |00002c10| 73 77 61 72 6d 2d 3e 62 | 65 65 59 5b 30 5d 29 3b |swarm->b|eeY[0]);| |00002c20| 0d 20 20 20 20 48 4c 6f | 63 6b 48 69 28 28 48 61 |. HLo|ckHi((Ha| |00002c30| 6e 64 6c 65 29 20 73 77 | 61 72 6d 2d 3e 62 65 65 |ndle) sw|arm->bee| |00002c40| 59 5b 31 5d 29 3b 0d 20 | 20 20 20 0d 20 20 20 20 |Y[1]);. | . | |00002c50| 48 4c 6f 63 6b 48 69 28 | 28 48 61 6e 64 6c 65 29 |HLockHi(|(Handle)| |00002c60| 20 73 77 61 72 6d 2d 3e | 62 65 65 56 65 6c 58 29 | swarm->|beeVelX)| |00002c70| 3b 20 0d 20 20 20 20 48 | 4c 6f 63 6b 48 69 28 28 |; . H|LockHi((| |00002c80| 48 61 6e 64 6c 65 29 20 | 73 77 61 72 6d 2d 3e 62 |Handle) |swarm->b| |00002c90| 65 65 56 65 6c 59 29 3b | 0d 0d 09 09 2f 2f 20 49 |eeVelY);|....// I| |00002ca0| 6e 69 74 69 61 6c 69 7a | 65 20 74 68 65 20 72 61 |nitializ|e the ra| |00002cb0| 6e 64 6f 6d 20 6e 75 6d | 62 65 72 20 67 65 6e 65 |ndom num|ber gene| |00002cc0| 72 61 74 6f 72 2e 0d 09 | 70 61 72 61 6d 73 2d 3e |rator...|params->| |00002cd0| 71 64 47 6c 6f 62 61 6c | 73 43 6f 70 79 2d 3e 71 |qdGlobal|sCopy->q| |00002ce0| 64 52 61 6e 64 53 65 65 | 64 20 3d 20 54 69 63 6b |dRandSee|d = Tick| |00002cf0| 43 6f 75 6e 74 28 29 3b | 0d 0d 09 09 2f 2f 20 53 |Count();|....// S| |00002d00| 77 61 72 6d 20 61 6e 69 | 6d 61 74 69 6f 6e 20 75 |warm ani|mation u| |00002d10| 73 65 73 20 2a 6f 6e 6c | 79 2a 20 74 68 65 20 6d |ses *onl|y* the m| |00002d20| 61 69 6e 20 6d 6f 6e 69 | 74 6f 72 20 28 2e 2e 2e |ain moni|tor (...| |00002d30| 5b 30 5d 29 2e 0d 09 09 | 2f 2f 20 54 68 69 73 20 |[0])....|// This | |00002d40| 77 69 6c 6c 20 63 68 61 | 6e 67 65 20 69 6e 20 74 |will cha|nge in t| |00002d50| 68 65 20 6e 65 78 74 20 | 72 65 6c 65 61 73 65 20 |he next |release | |00002d60| 6f 66 20 74 68 69 73 20 | 6d 6f 64 75 6c 65 2e 0d |of this |module..| |00002d70| 20 20 20 20 73 77 61 72 | 6d 2d 3e 6d 6f 6e 69 74 | swar|m->monit| |00002d80| 6f 72 52 65 63 74 20 3d | 20 70 61 72 61 6d 73 2d |orRect =| params-| |00002d90| 3e 6d 6f 6e 69 74 6f 72 | 73 2d 3e 6d 6f 6e 69 74 |>monitor|s->monit| |00002da0| 6f 72 4c 69 73 74 5b 30 | 5d 2e 62 6f 75 6e 64 73 |orList[0|].bounds| |00002db0| 3b 0d 20 20 20 20 73 77 | 61 72 6d 2d 3e 77 69 6e |;. sw|arm->win| |00002dc0| 57 20 20 20 3d 20 73 77 | 61 72 6d 2d 3e 6d 6f 6e |W = sw|arm->mon| |00002dd0| 69 74 6f 72 52 65 63 74 | 2e 72 69 67 68 74 20 2d |itorRect|.right -| |00002de0| 20 73 77 61 72 6d 2d 3e | 6d 6f 6e 69 74 6f 72 52 | swarm->|monitorR| |00002df0| 65 63 74 2e 6c 65 66 74 | 3b 20 20 20 20 20 0d 20 |ect.left|; . | |00002e00| 20 20 20 73 77 61 72 6d | 2d 3e 77 69 6e 48 20 20 | swarm|->winH | |00002e10| 20 3d 20 73 77 61 72 6d | 2d 3e 6d 6f 6e 69 74 6f | = swarm|->monito| |00002e20| 72 52 65 63 74 2e 62 6f | 74 74 6f 6d 20 2d 20 73 |rRect.bo|ttom - s| |00002e30| 77 61 72 6d 2d 3e 6d 6f | 6e 69 74 6f 72 52 65 63 |warm->mo|nitorRec| |00002e40| 74 2e 74 6f 70 3b 0d 20 | 20 20 20 0d 20 20 20 20 |t.top;. | . | |00002e50| 09 2f 2f 20 46 6f 72 20 | 64 69 66 66 65 72 65 6e |.// For |differen| |00002e60| 74 20 6d 6f 6e 69 74 6f | 72 20 73 69 7a 65 73 2c |t monito|r sizes,| |00002e70| 20 77 65 20 77 61 6e 74 | 20 74 68 65 20 72 65 6c | we want| the rel| |00002e80| 61 74 69 6f 6e 20 62 65 | 74 77 65 65 6e 0d 20 20 |ation be|tween. | |00002e90| 20 20 09 2f 2f 20 62 6f | 72 64 65 72 20 61 6e 64 | .// bo|rder and| |00002ea0| 20 77 69 6e 57 20 74 6f | 20 62 65 20 74 68 65 20 | winW to| be the | |00002eb0| 73 61 6d 65 20 61 73 20 | 74 68 61 74 20 62 65 74 |same as |that bet| |00002ec0| 77 65 65 6e 20 42 4f 52 | 44 45 52 20 61 6e 64 20 |ween BOR|DER and | |00002ed0| 36 34 30 0d 20 20 20 20 | 09 2f 2f 20 28 6d 79 20 |640. |.// (my | |00002ee0| 31 33 22 20 73 63 72 65 | 65 6e 29 2e 20 54 68 65 |13" scre|en). The| |00002ef0| 20 63 61 73 74 20 74 6f | 20 27 6c 6f 6e 67 27 20 | cast to| 'long' | |00002f00| 69 73 20 62 65 63 61 75 | 73 65 20 74 68 65 20 6d |is becau|se the m| |00002f10| 75 6c 74 69 70 6c 69 63 | 61 74 69 6f 6e 0d 20 20 |ultiplic|ation. | |00002f20| 20 20 09 2f 2f 20 77 69 | 6c 6c 20 6f 76 65 72 66 | .// wi|ll overf| |00002f30| 6c 6f 77 20 61 20 32 2d | 62 79 74 65 20 69 6e 74 |low a 2-|byte int| |00002f40| 20 66 6f 72 20 6c 61 72 | 67 65 20 6d 6f 6e 69 74 | for lar|ge monit| |00002f50| 6f 72 73 2e 20 59 6f 75 | 20 68 61 76 65 20 6e 6f |ors. You| have no| |00002f60| 20 2a 69 64 65 61 2a 0d | 20 20 20 20 09 2f 2f 20 | *idea*.| .// | |00002f70| 68 6f 77 20 6c 6f 6e 67 | 20 69 74 20 74 6f 6f 6b |how long| it took| |00002f80| 20 6d 65 20 74 6f 20 64 | 69 73 63 6f 76 65 72 20 | me to d|iscover | |00002f90| 74 68 69 73 20 6f 6e 65 | 20 28 70 72 69 6d 61 72 |this one| (primar| |00002fa0| 69 6c 79 20 62 65 63 61 | 75 73 65 20 49 20 64 6f |ily beca|use I do| |00002fb0| 6e 27 74 0d 20 20 20 20 | 09 2f 2f 20 2a 68 61 76 |n't. |.// *hav| |00002fc0| 65 2a 20 61 20 6c 61 72 | 67 65 20 6d 6f 6e 69 74 |e* a lar|ge monit| |00002fd0| 6f 72 29 2e 0d 20 20 20 | 20 73 77 61 72 6d 2d 3e |or).. | swarm->| |00002fe0| 62 6f 72 64 65 72 20 3d | 20 28 28 6c 6f 6e 67 29 |border =| ((long)| |00002ff0| 20 42 4f 52 44 45 52 20 | 2a 20 73 77 61 72 6d 2d | BORDER |* swarm-| |00003000| 3e 77 69 6e 57 29 20 2f | 20 36 34 30 3b 0d 20 20 |>winW) /| 640;. | |00003010| 20 20 0d 20 20 20 20 09 | 2f 2f 20 49 6e 69 74 69 | . .|// Initi| |00003020| 61 6c 69 73 65 20 76 61 | 72 69 61 62 6c 65 73 20 |alise va|riables | |00003030| 77 69 74 68 20 65 61 72 | 6c 69 65 72 20 64 65 66 |with ear|lier def| |00003040| 69 6e 65 64 20 63 6f 6e | 73 74 61 6e 74 73 2e 0d |ined con|stants..| |00003050| 20 20 20 20 73 77 61 72 | 6d 2d 3e 6d 61 78 51 75 | swar|m->maxQu| |00003060| 65 65 6e 56 65 6c 20 3d | 20 51 55 45 45 4e 56 45 |eenVel =| QUEENVE| |00003070| 4c 3b 0d 20 20 20 20 73 | 77 61 72 6d 2d 3e 6d 61 |L;. s|warm->ma| |00003080| 78 42 65 65 56 65 6c 20 | 20 3d 20 42 45 45 56 45 |xBeeVel | = BEEVE| |00003090| 4c 3b 0d 20 20 20 20 73 | 77 61 72 6d 2d 3e 6d 61 |L;. s|warm->ma| |000030a0| 78 51 75 65 65 6e 41 63 | 63 20 3d 20 51 55 45 45 |xQueenAc|c = QUEE| |000030b0| 4e 41 43 43 3b 0d 20 20 | 20 20 73 77 61 72 6d 2d |NACC;. | swarm-| |000030c0| 3e 6d 61 78 42 65 65 41 | 63 63 20 20 3d 20 42 45 |>maxBeeA|cc = BE| |000030d0| 45 41 43 43 3b 0d 20 20 | 20 20 0d 20 20 20 20 09 |EACC;. | . .| |000030e0| 2f 2f 20 4d 61 6b 65 20 | 62 6f 74 68 20 62 6f 75 |// Make |both bou| |000030f0| 6e 64 69 6e 67 20 72 65 | 63 74 61 6e 67 6c 65 73 |nding re|ctangles| |00003100| 20 69 6e 74 69 61 6c 6c | 79 20 65 6d 70 74 79 2e | intiall|y empty.| |00003110| 0d 20 20 20 20 53 65 74 | 52 65 63 74 28 26 73 77 |. Set|Rect(&sw| |00003120| 61 72 6d 2d 3e 6f 6c 64 | 52 65 63 74 2c 20 30 2c |arm->old|Rect, 0,| |00003130| 20 30 2c 20 30 2c 20 30 | 29 3b 0d 20 20 20 20 53 | 0, 0, 0|);. S| |00003140| 65 74 52 65 63 74 28 26 | 73 77 61 72 6d 2d 3e 73 |etRect(&|swarm->s| |00003150| 77 61 72 6d 52 65 63 74 | 2c 20 30 2c 20 30 2c 20 |warmRect|, 0, 0, | |00003160| 30 2c 20 30 29 3b 0d 20 | 20 20 20 20 20 20 20 0d |0, 0);. | .| |00003170| 20 20 20 20 20 20 20 20 | 2f 2f 20 49 6e 69 74 69 | |// Initi| |00003180| 61 6c 20 51 75 65 65 6e | 20 70 6f 73 69 74 69 6f |al Queen| positio| |00003190| 6e 2e 0d 20 20 20 20 51 | 58 28 30 29 20 3d 20 52 |n.. Q|X(0) = R| |000031a0| 61 6e 67 65 64 52 64 6d | 28 73 77 61 72 6d 2d 3e |angedRdm|(swarm->| |000031b0| 62 6f 72 64 65 72 2c 20 | 73 77 61 72 6d 2d 3e 77 |border, |swarm->w| |000031c0| 69 6e 57 20 2d 20 73 77 | 61 72 6d 2d 3e 62 6f 72 |inW - sw|arm->bor| |000031d0| 64 65 72 29 3b 0d 09 51 | 59 28 30 29 20 3d 20 52 |der);..Q|Y(0) = R| |000031e0| 61 6e 67 65 64 52 64 6d | 28 73 77 61 72 6d 2d 3e |angedRdm|(swarm->| |000031f0| 62 6f 72 64 65 72 2c 20 | 73 77 61 72 6d 2d 3e 77 |border, |swarm->w| |00003200| 69 6e 48 20 2d 20 73 77 | 61 72 6d 2d 3e 62 6f 72 |inH - sw|arm->bor| |00003210| 64 65 72 29 3b 0d 0d 09 | 09 2f 2f 20 49 66 20 69 |der);...|.// If i| |00003220| 6e 20 64 65 6d 6f 20 6d | 6f 64 65 2c 20 74 68 65 |n demo m|ode, the| |00003230| 6e 20 6d 61 6b 65 20 73 | 75 72 65 20 74 68 61 74 |n make s|ure that| |00003240| 20 74 68 65 0d 09 09 2f | 2f 20 69 6e 69 74 69 61 | the.../|/ initia| |00003250| 6c 20 51 75 65 65 6e 20 | 70 6f 73 69 74 69 6f 6e |l Queen |position| |00003260| 20 6c 69 65 73 20 61 74 | 20 6c 65 61 73 74 20 27 | lies at| least '| |00003270| 62 6f 72 64 65 72 27 20 | 70 69 78 65 6c 73 20 2a |border' |pixels *| |00003280| 6f 75 74 73 69 64 65 2a | 20 74 68 65 20 64 65 6d |outside*| the dem| |00003290| 6f 52 65 63 74 21 0d 20 | 20 20 20 69 66 20 28 73 |oRect!. | if (s| |000032a0| 77 61 72 6d 2d 3e 64 65 | 6d 6f 4d 6f 64 65 29 0d |warm->de|moMode).| |000032b0| 20 20 20 20 7b 0d 09 20 | 20 20 20 62 6f 72 64 65 | {.. | borde| |000032c0| 72 65 64 44 65 6d 6f 52 | 65 63 74 20 3d 20 70 61 |redDemoR|ect = pa| |000032d0| 72 61 6d 73 2d 3e 64 65 | 6d 6f 52 65 63 74 3b 0d |rams->de|moRect;.| |000032e0| 09 20 20 20 20 49 6e 73 | 65 74 52 65 63 74 28 26 |. Ins|etRect(&| |000032f0| 62 6f 72 64 65 72 65 64 | 44 65 6d 6f 52 65 63 74 |bordered|DemoRect| |00003300| 2c 20 2d 73 77 61 72 6d | 2d 3e 62 6f 72 64 65 72 |, -swarm|->border| |00003310| 2c 20 2d 73 77 61 72 6d | 2d 3e 62 6f 72 64 65 72 |, -swarm|->border| |00003320| 29 3b 0d 0d 09 20 20 20 | 20 77 68 69 6c 65 20 28 |);... | while (| |00003330| 58 59 49 6e 52 65 63 74 | 28 26 62 6f 72 64 65 72 |XYInRect|(&border| |00003340| 65 64 44 65 6d 6f 52 65 | 63 74 2c 20 51 58 28 30 |edDemoRe|ct, QX(0| |00003350| 29 2c 20 51 59 28 30 29 | 29 29 0d 09 20 20 20 20 |), QY(0)|)).. | |00003360| 7b 0d 09 20 20 20 20 09 | 51 58 28 30 29 20 3d 20 |{.. .|QX(0) = | |00003370| 52 61 6e 67 65 64 52 64 | 6d 28 73 77 61 72 6d 2d |RangedRd|m(swarm-| |00003380| 3e 62 6f 72 64 65 72 2c | 20 73 77 61 72 6d 2d 3e |>border,| swarm->| |00003390| 77 69 6e 57 20 2d 20 73 | 77 61 72 6d 2d 3e 62 6f |winW - s|warm->bo| |000033a0| 72 64 65 72 29 3b 0d 09 | 20 20 20 20 09 51 59 28 |rder);..| .QY(| |000033b0| 30 29 20 3d 20 52 61 6e | 67 65 64 52 64 6d 28 73 |0) = Ran|gedRdm(s| |000033c0| 77 61 72 6d 2d 3e 62 6f | 72 64 65 72 2c 20 73 77 |warm->bo|rder, sw| |000033d0| 61 72 6d 2d 3e 77 69 6e | 48 20 2d 20 73 77 61 72 |arm->win|H - swar| |000033e0| 6d 2d 3e 62 6f 72 64 65 | 72 29 3b 0d 09 20 20 20 |m->borde|r);.. | |000033f0| 20 7d 0d 09 7d 0d 0d 09 | 09 2f 2f 20 46 6f 72 20 | }..}...|.// For | |00003400| 74 68 65 20 66 69 72 73 | 74 20 66 72 61 6d 65 2c |the firs|t frame,| |00003410| 20 6f 75 72 20 6c 69 6e | 65 20 73 65 67 6d 65 6e | our lin|e segmen| |00003420| 74 20 69 73 20 6a 75 73 | 74 20 61 20 70 6f 69 6e |t is jus|t a poin| |00003430| 74 2e 0d 20 20 20 20 51 | 58 28 31 29 20 3d 20 51 |t.. Q|X(1) = Q| |00003440| 58 28 30 29 3b 0d 20 20 | 20 20 51 59 28 31 29 20 |X(0);. | QY(1) | |00003450| 3d 20 51 59 28 30 29 3b | 0d 20 20 20 20 51 58 56 |= QY(0);|. QXV| |00003460| 20 3d 20 51 59 56 20 3d | 20 30 3b 0d 20 20 20 20 | = QYV =| 0;. | |00003470| 0d 20 20 20 20 09 2f 2f | 20 44 69 74 74 6f 20 66 |. .//| Ditto f| |00003480| 6f 72 20 74 68 65 20 42 | 65 65 73 2c 20 61 6c 74 |or the B|ees, alt| |00003490| 68 6f 75 67 68 20 28 61 | 29 20 61 6c 6c 20 42 65 |hough (a|) all Be| |000034a0| 65 73 20 73 74 61 72 74 | 20 66 72 6f 6d 20 74 68 |es start| from th| |000034b0| 65 20 73 61 6d 65 0d 20 | 20 20 20 09 2f 2f 20 70 |e same. | .// p| |000034c0| 68 79 73 69 63 61 6c 20 | 70 6f 73 69 74 69 6f 6e |hysical |position| |000034d0| 20 61 73 20 74 68 65 20 | 51 75 65 65 6e 2c 20 61 | as the |Queen, a| |000034e0| 6e 64 20 28 62 29 20 61 | 6c 6c 20 42 65 65 73 20 |nd (b) a|ll Bees | |000034f0| 68 61 76 65 20 61 20 64 | 69 66 66 65 72 65 6e 74 |have a d|ifferent| |00003500| 0d 20 20 20 20 09 2f 2f | 20 69 6e 69 74 69 61 6c |. .//| initial| |00003510| 20 76 65 6c 6f 63 69 74 | 79 2e 20 54 68 69 73 20 | velocit|y. This | |00003520| 67 69 76 65 73 20 61 20 | 6e 69 63 65 20 27 66 6f |gives a |nice 'fo| |00003530| 75 6e 74 61 69 6e 69 6e | 67 27 20 65 66 66 65 63 |untainin|g' effec| |00003540| 74 20 6f 6e 20 73 74 61 | 72 74 75 70 0d 20 20 20 |t on sta|rtup. | |00003550| 20 09 2f 2f 20 6f 66 20 | 74 68 65 20 61 6e 69 6d | .// of |the anim| |00003560| 61 74 69 6f 6e 2e 0d 20 | 20 20 20 66 6f 72 20 28 |ation.. | for (| |00003570| 62 20 3d 20 30 3b 20 62 | 20 3c 20 4d 41 58 42 45 |b = 0; b| < MAXBE| |00003580| 45 53 3b 20 62 2b 2b 29 | 0d 20 20 20 20 7b 0d 20 |ES; b++)|. {. | |00003590| 20 20 20 20 20 20 20 42 | 58 28 30 2c 62 29 20 3d | B|X(0,b) =| |000035a0| 20 51 58 28 30 29 3b 0d | 20 20 20 20 20 20 20 20 | QX(0);.| | |000035b0| 42 58 28 31 2c 62 29 20 | 3d 20 42 58 28 30 2c 62 |BX(1,b) |= BX(0,b| |000035c0| 29 3b 0d 20 20 20 20 20 | 20 20 20 42 59 28 30 2c |);. | BY(0,| |000035d0| 62 29 20 3d 20 51 59 28 | 30 29 3b 0d 20 20 20 20 |b) = QY(|0);. | |000035e0| 20 20 20 20 42 59 28 31 | 2c 62 29 20 3d 20 42 59 | BY(1|,b) = BY| |000035f0| 28 30 2c 62 29 3b 0d 0d | 20 20 20 20 20 20 20 20 |(0,b);..| | |00003600| 42 58 56 28 62 29 20 3d | 20 52 41 4e 44 28 37 29 |BXV(b) =| RAND(7)| |00003610| 3b 0d 20 20 20 20 20 20 | 20 20 42 59 56 28 62 29 |;. | BYV(b)| |00003620| 20 3d 20 52 41 4e 44 28 | 37 29 3b 0d 20 20 20 20 | = RAND(|7);. | |00003630| 7d 0d 09 09 0d 09 09 2f | 2f 20 4e 6f 77 20 61 6c |}....../|/ Now al| |00003640| 6c 6f 63 61 74 65 20 61 | 6e 20 6f 66 66 73 63 72 |locate a|n offscr| |00003650| 65 65 6e 20 67 72 61 70 | 68 69 63 73 20 77 6f 72 |een grap|hics wor| |00003660| 6c 64 2c 20 77 68 65 72 | 65 20 77 65 20 63 61 6e |ld, wher|e we can| |00003670| 20 64 6f 0d 09 09 2f 2f | 20 66 61 73 74 20 64 72 | do...//| fast dr| |00003680| 61 77 69 6e 67 20 77 69 | 74 68 6f 75 74 20 64 69 |awing wi|thout di| |00003690| 73 74 75 72 62 69 6e 67 | 20 74 68 65 20 72 65 61 |sturbing| the rea| |000036a0| 6c 20 73 63 72 65 65 6e | 2e 0d 09 09 2f 2f 20 49 |l screen|....// I| |000036b0| 20 72 65 63 6f 6d 6d 65 | 6e 64 20 6c 6f 6f 6b 69 | recomme|nd looki| |000036c0| 6e 67 20 75 70 20 74 68 | 69 73 20 63 61 6c 6c 20 |ng up th|is call | |000036d0| 69 6e 20 49 6e 73 69 64 | 65 20 4d 61 63 69 6e 74 |in Insid|e Macint| |000036e0| 6f 73 68 20 6f 72 20 54 | 68 69 6e 6b 20 52 65 66 |osh or T|hink Ref| |000036f0| 65 72 65 6e 63 65 21 0d | 09 2f 2f 69 66 20 28 4e |erence!.|.//if (N| |00003700| 65 77 47 57 6f 72 6c 64 | 28 26 28 73 77 61 72 6d |ewGWorld|(&(swarm| |00003710| 2d 3e 67 4d 79 4f 66 66 | 47 29 2c 20 30 2c 20 26 |->gMyOff|G), 0, &| |00003720| 28 28 2a 2a 62 6c 61 6e | 6b 52 67 6e 29 2e 72 67 |((**blan|kRgn).rg| |00003730| 6e 42 42 6f 78 29 2c 20 | 6e 69 6c 2c 20 6e 69 6c |nBBox), |nil, nil| |00003740| 2c 20 6e 6f 4e 65 77 44 | 65 76 69 63 65 29 20 21 |, noNewD|evice) !| |00003750| 3d 20 6e 6f 45 72 72 29 | 20 20 09 0d 09 2f 2f 69 |= noErr)| ...//i| |00003760| 66 20 28 4e 65 77 47 57 | 6f 72 6c 64 28 26 28 73 |f (NewGW|orld(&(s| |00003770| 77 61 72 6d 2d 3e 67 4d | 79 4f 66 66 47 29 2c 20 |warm->gM|yOffG), | |00003780| 30 2c 20 26 28 73 77 61 | 72 6d 2d 3e 6d 6f 6e 69 |0, &(swa|rm->moni| |00003790| 74 6f 72 52 65 63 74 29 | 2c 20 6e 69 6c 2c 20 6e |torRect)|, nil, n| |000037a0| 69 6c 2c 20 6e 6f 4e 65 | 77 44 65 76 69 63 65 29 |il, noNe|wDevice)| |000037b0| 20 21 3d 20 6e 6f 45 72 | 72 29 20 20 09 0d 09 69 | != noEr|r) ...i| |000037c0| 66 20 28 4e 65 77 47 57 | 6f 72 6c 64 28 26 28 73 |f (NewGW|orld(&(s| |000037d0| 77 61 72 6d 2d 3e 67 4d | 79 4f 66 66 47 29 2c 20 |warm->gM|yOffG), | |000037e0| 30 2c 20 26 28 73 77 61 | 72 6d 2d 3e 6d 6f 6e 69 |0, &(swa|rm->moni| |000037f0| 74 6f 72 52 65 63 74 29 | 2c 20 6e 69 6c 2c 20 6e |torRect)|, nil, n| |00003800| 69 6c 2c 20 6e 6f 4e 65 | 77 44 65 76 69 63 65 2b |il, noNe|wDevice+| |00003810| 75 73 65 54 65 6d 70 4d | 65 6d 29 20 21 3d 20 6e |useTempM|em) != n| |00003820| 6f 45 72 72 29 20 20 09 | 0d 09 7b 20 09 0d 09 09 |oErr) .|..{ ....| |00003830| 44 6f 43 6c 6f 73 65 28 | 2a 73 74 6f 72 61 67 65 |DoClose(|*storage| |00003840| 2c 20 28 52 67 6e 48 61 | 6e 64 6c 65 29 20 6e 69 |, (RgnHa|ndle) ni| |00003850| 6c 2c 20 28 47 4d 50 61 | 72 61 6d 42 6c 6f 63 6b |l, (GMPa|ramBlock| |00003860| 50 74 72 29 20 6e 69 6c | 29 3b 0d 09 09 45 72 72 |Ptr) nil|);...Err| |00003870| 6f 72 4d 73 67 28 22 54 | 68 65 20 53 77 61 72 6d |orMsg("T|he Swarm| |00003880| 3a 20 20 4e 6f 74 20 65 | 6e 6f 75 67 68 20 6d 65 |: Not e|nough me| |00003890| 6d 6f 72 79 20 66 6f 72 | 20 6f 66 66 73 63 72 65 |mory for| offscre| |000038a0| 65 6e 20 67 72 61 70 68 | 69 63 73 20 77 6f 72 6c |en graph|ics worl| |000038b0| 64 21 22 29 3b 0d 09 09 | 72 65 74 75 72 6e 20 4d |d!");...|return M| |000038c0| 6f 64 75 6c 65 45 72 72 | 6f 72 3b 09 09 09 0d 09 |oduleErr|or;.....| |000038d0| 7d 0d 0d 09 48 55 6e 6c | 6f 63 6b 28 2a 73 74 6f |}...HUnl|ock(*sto| |000038e0| 72 61 67 65 29 3b 0d 09 | 09 0d 09 72 65 74 75 72 |rage);..|...retur| |000038f0| 6e 20 6e 6f 45 72 72 3b | 0d 7d 0d 0d 0d 09 2f 2f |n noErr;|.}....//| |00003900| 20 4e 65 78 74 2c 20 74 | 68 65 20 44 6f 42 6c 61 | Next, t|he DoBla| |00003910| 6e 6b 20 66 75 6e 63 74 | 69 6f 6e 2e 20 54 68 69 |nk funct|ion. Thi| |00003920| 73 20 66 75 6e 63 74 69 | 6f 6e 20 70 65 72 66 6f |s functi|on perfo| |00003930| 72 6d 73 20 74 77 6f 20 | 74 61 73 6b 73 3a 20 69 |rms two |tasks: i| |00003940| 74 20 62 6c 61 6e 6b 73 | 0d 09 2f 2f 20 6f 75 74 |t blanks|..// out| |00003950| 20 74 68 65 20 72 65 61 | 6c 20 73 63 72 65 65 6e | the rea|l screen| |00003960| 20 28 6f 6e 20 61 6c 6c | 20 6d 6f 6e 69 74 6f 72 | (on all| monitor| |00003970| 73 2c 20 6e 6f 74 20 6a | 75 73 74 20 74 68 65 20 |s, not j|ust the | |00003980| 6d 61 69 6e 20 6d 6f 6e | 69 74 6f 72 20 77 65 20 |main mon|itor we | |00003990| 75 73 65 20 66 6f 72 20 | 74 68 65 0d 09 2f 2f 20 |use for |the..// | |000039a0| 61 6e 69 6d 61 74 69 6f | 6e 29 2c 20 61 6e 64 20 |animatio|n), and | |000039b0| 69 74 20 61 6c 73 6f 20 | 62 6c 61 6e 6b 73 20 6f |it also |blanks o| |000039c0| 75 74 20 74 68 65 20 6f | 66 66 77 6f 72 6c 64 20 |ut the o|ffworld | |000039d0| 73 63 72 65 65 6e 2e 0d | 0d 4f 53 45 72 72 0d 44 |screen..|.OSErr.D| |000039e0| 6f 42 6c 61 6e 6b 28 48 | 61 6e 64 6c 65 20 73 74 |oBlank(H|andle st| |000039f0| 6f 72 61 67 65 2c 20 52 | 67 6e 48 61 6e 64 6c 65 |orage, R|gnHandle| |00003a00| 20 62 6c 61 6e 6b 52 67 | 6e 2c 20 47 4d 50 61 72 | blankRg|n, GMPar| |00003a10| 61 6d 42 6c 6f 63 6b 50 | 74 72 20 70 61 72 61 6d |amBlockP|tr param| |00003a20| 73 29 0d 7b 0d 20 20 20 | 20 72 65 67 69 73 74 65 |s).{. | registe| |00003a30| 72 20 53 77 61 72 6d 53 | 74 6f 72 61 67 65 50 74 |r SwarmS|toragePt| |00003a40| 72 20 73 77 61 72 6d 3b | 0d 20 20 20 20 20 20 20 |r swarm;|. | |00003a50| 20 0d 20 20 20 20 47 57 | 6f 72 6c 64 50 74 72 09 | . GW|orldPtr.| |00003a60| 09 63 75 72 72 50 6f 72 | 74 3b 09 2f 2f 20 54 68 |.currPor|t;.// Th| |00003a70| 65 20 27 72 65 61 6c 27 | 20 73 63 72 65 65 6e 20 |e 'real'| screen | |00003a80| 63 6f 6e 73 69 73 74 73 | 20 6f 66 20 74 77 6f 20 |consists| of two | |00003a90| 63 6f 6d 70 6f 6e 65 6e | 74 73 0d 09 47 44 48 61 |componen|ts..GDHa| |00003aa0| 6e 64 6c 65 09 09 63 75 | 72 72 44 65 76 3b 09 2f |ndle..cu|rrDev;./| |00003ab0| 2f 20 77 68 69 63 68 20 | 77 65 27 6c 6c 20 73 61 |/ which |we'll sa| |00003ac0| 76 65 20 69 6e 20 74 68 | 65 73 65 20 76 61 72 69 |ve in th|ese vari| |00003ad0| 61 62 6c 65 73 2e 0d 0d | 20 20 20 20 48 4c 6f 63 |ables...| HLoc| |00003ae0| 6b 48 69 28 73 74 6f 72 | 61 67 65 29 3b 0d 20 20 |kHi(stor|age);. | |00003af0| 20 20 73 77 61 72 6d 20 | 3d 20 28 53 77 61 72 6d | swarm |= (Swarm| |00003b00| 53 74 6f 72 61 67 65 50 | 74 72 29 20 2a 73 74 6f |StorageP|tr) *sto| |00003b10| 72 61 67 65 3b 0d 20 20 | 20 20 0d 20 20 20 20 09 |rage;. | . .| |00003b20| 2f 2f 20 53 61 76 65 20 | 74 68 65 20 27 72 65 61 |// Save |the 'rea| |00003b30| 6c 27 20 73 63 72 65 65 | 6e 2e 0d 09 47 65 74 47 |l' scree|n...GetG| |00003b40| 57 6f 72 6c 64 28 26 63 | 75 72 72 50 6f 72 74 2c |World(&c|urrPort,| |00003b50| 26 63 75 72 72 44 65 76 | 29 3b 0d 09 0d 09 09 2f |&currDev|);...../| |00003b60| 2f 20 53 77 69 74 63 68 | 20 74 6f 20 74 68 65 20 |/ Switch| to the | |00003b70| 6f 66 66 73 63 72 65 65 | 6e 20 77 6f 72 6c 64 2e |offscree|n world.| |00003b80| 0d 09 53 65 74 47 57 6f | 72 6c 64 28 28 73 77 61 |..SetGWo|rld((swa| |00003b90| 72 6d 2d 3e 67 4d 79 4f | 66 66 47 29 2c 20 6e 69 |rm->gMyO|ffG), ni| |00003ba0| 6c 29 3b 0d 09 0d 09 09 | 2f 2f 20 53 65 74 20 74 |l);.....|// Set t| |00003bb0| 68 65 20 62 61 63 6b 67 | 72 6f 75 6e 64 63 6f 6c |he backg|roundcol| |00003bc0| 6f 72 2c 20 61 6e 64 20 | 65 72 61 73 65 20 74 68 |or, and |erase th| |00003bd0| 65 20 77 68 6f 6c 65 20 | 77 6f 72 6c 64 2e 0d 20 |e whole |world.. | |00003be0| 20 20 09 52 47 42 42 61 | 63 6b 43 6f 6c 6f 72 28 | .RGBBa|ckColor(| |00003bf0| 26 73 77 61 72 6d 2d 3e | 62 61 63 6b 52 47 42 29 |&swarm->|backRGB)| |00003c00| 3b 0d 09 45 72 61 73 65 | 52 67 6e 28 62 6c 61 6e |;..Erase|Rgn(blan| |00003c10| 6b 52 67 6e 29 3b 0d 09 | 0d 09 09 2f 2f 20 53 77 |kRgn);..|...// Sw| |00003c20| 69 74 63 68 20 62 61 63 | 6b 20 74 6f 20 74 68 65 |itch bac|k to the| |00003c30| 20 27 72 65 61 6c 27 20 | 73 63 72 65 65 6e 2e 0d | 'real' |screen..| |00003c40| 09 53 65 74 47 57 6f 72 | 6c 64 20 28 63 75 72 72 |.SetGWor|ld (curr| |00003c50| 50 6f 72 74 2c 20 63 75 | 72 72 44 65 76 29 3b 0d |Port, cu|rrDev);.| |00003c60| 09 0d 09 09 2f 2f 20 54 | 68 69 73 20 69 73 20 6e |....// T|his is n| |00003c70| 6f 74 20 72 65 64 75 6e | 64 61 6e 74 21 20 57 65 |ot redun|dant! We| |00003c80| 20 61 72 65 20 69 6e 20 | 61 20 64 69 66 66 65 72 | are in |a differ| |00003c90| 65 6e 74 20 77 6f 72 6c | 64 20 6e 6f 77 2e 2e 2e |ent worl|d now...| |00003ca0| 0d 20 20 20 09 52 47 42 | 42 61 63 6b 43 6f 6c 6f |. .RGB|BackColo| |00003cb0| 72 28 26 73 77 61 72 6d | 2d 3e 62 61 63 6b 52 47 |r(&swarm|->backRG| |00003cc0| 42 29 3b 0d 0d 09 09 2f | 2f 20 44 6f 20 61 20 6e |B);..../|/ Do a n| |00003cd0| 69 63 65 20 66 61 64 65 | 2d 6f 75 74 2f 66 61 64 |ice fade|-out/fad| |00003ce0| 65 2d 69 6e 20 69 66 20 | 74 68 65 20 75 73 65 72 |e-in if |the user| |00003cf0| 20 73 70 65 63 69 66 69 | 65 64 0d 09 09 2f 2f 20 | specifi|ed...// | |00003d00| 74 68 61 74 20 63 68 65 | 63 6b 20 62 6f 78 20 69 |that che|ck box i| |00003d10| 6e 20 74 68 65 20 43 6f | 6e 74 72 6f 6c 20 50 61 |n the Co|ntrol Pa| |00003d20| 6e 65 6c 2c 20 61 6e 64 | 20 69 66 20 74 68 65 20 |nel, and| if the | |00003d30| 6d 6f 6e 69 74 6f 72 0d | 09 09 2f 2f 20 69 73 20 |monitor.|..// is | |00003d40| 63 61 70 61 62 6c 65 20 | 6f 66 20 64 6f 69 6e 67 |capable |of doing| |00003d50| 20 73 6f 2e 0d 09 09 2f | 2f 20 54 68 65 20 72 6f | so..../|/ The ro| |00003d60| 75 74 69 6e 65 73 20 49 | 20 75 73 65 20 61 72 65 |utines I| use are| |00003d70| 20 2a 6f 6e 6c 79 2a 20 | 66 69 74 20 66 6f 72 20 | *only* |fit for | |00003d80| 38 2d 62 69 74 20 43 4c | 55 54 20 64 69 73 70 6c |8-bit CL|UT displ| |00003d90| 61 79 73 2c 20 73 6f 0d | 09 09 2f 2f 20 64 6f 6e |ays, so.|..// don| |00003da0| 27 74 20 65 76 65 72 20 | 74 72 79 20 63 68 61 6e |'t ever |try chan| |00003db0| 67 69 6e 67 20 74 68 69 | 73 21 0d 09 69 66 20 28 |ging thi|s!..if (| |00003dc0| 70 61 72 61 6d 73 2d 3e | 63 6f 6e 74 72 6f 6c 56 |params->|controlV| |00003dd0| 61 6c 75 65 73 5b 32 5d | 20 26 26 20 70 61 72 61 |alues[2]| && para| |00003de0| 6d 73 2d 3e 6d 6f 6e 69 | 74 6f 72 73 2d 3e 6d 6f |ms->moni|tors->mo| |00003df0| 6e 69 74 6f 72 4c 69 73 | 74 5b 30 5d 2e 63 75 72 |nitorLis|t[0].cur| |00003e00| 44 65 70 74 68 20 3d 3d | 20 38 29 0d 20 20 20 20 |Depth ==| 8). | |00003e10| 7b 0d 20 20 20 20 09 66 | 61 64 65 5f 73 63 72 65 |{. .f|ade_scre| |00003e20| 65 6e 28 32 30 30 2c 74 | 72 75 65 29 3b 0d 09 09 |en(200,t|rue);...| |00003e30| 45 72 61 73 65 52 67 6e | 28 62 6c 61 6e 6b 52 67 |EraseRgn|(blankRg| |00003e40| 6e 29 3b 0d 20 20 20 09 | 09 66 61 64 65 5f 73 63 |n);. .|.fade_sc| |00003e50| 72 65 65 6e 28 36 34 2c | 66 61 6c 73 65 29 3b 0d |reen(64,|false);.| |00003e60| 20 20 20 09 7d 0d 20 20 | 20 09 65 6c 73 65 0d 20 | .}. | .else. | |00003e70| 20 20 09 09 45 72 61 73 | 65 52 67 6e 28 62 6c 61 | ..Eras|eRgn(bla| |00003e80| 6e 6b 52 67 6e 29 3b 0d | 20 20 20 09 09 0d 20 20 |nkRgn);.| ... | |00003e90| 20 09 48 55 6e 6c 6f 63 | 6b 28 73 74 6f 72 61 67 | .HUnloc|k(storag| |00003ea0| 65 29 3b 0d 0d 20 20 20 | 20 72 65 74 75 72 6e 20 |e);.. | return | |00003eb0| 6e 6f 45 72 72 3b 0d 7d | 0d 0d 0d 09 2f 2f 20 48 |noErr;.}|....// H| |00003ec0| 61 2c 20 66 69 6e 61 6c | 6c 79 20 77 65 20 63 6f |a, final|ly we co| |00003ed0| 6d 65 20 74 6f 20 74 68 | 65 20 6d 65 61 74 20 6f |me to th|e meat o| |00003ee0| 66 20 6f 75 72 20 6d 6f | 64 75 6c 65 3a 20 74 68 |f our mo|dule: th| |00003ef0| 65 20 44 6f 44 72 61 77 | 46 72 61 6d 65 20 66 75 |e DoDraw|Frame fu| |00003f00| 6e 63 74 69 6f 6e 2e 0d | 09 2f 2f 20 41 6c 74 68 |nction..|.// Alth| |00003f10| 6f 75 67 68 20 74 68 65 | 72 65 20 69 73 20 61 20 |ough the|re is a | |00003f20| 6c 6f 74 20 6f 66 20 63 | 6f 64 65 20 68 65 72 65 |lot of c|ode here| |00003f30| 2c 20 77 68 61 74 20 61 | 63 74 75 61 6c 6c 79 20 |, what a|ctually | |00003f40| 68 61 70 70 65 6e 73 20 | 69 73 20 71 75 69 74 65 |happens |is quite| |00003f50| 20 73 69 6d 70 6c 65 2e | 0d 09 2f 2f 20 46 69 72 | simple.|..// Fir| |00003f60| 73 74 2c 20 61 6c 6c 20 | 74 68 65 20 70 6f 73 69 |st, all |the posi| |00003f70| 74 69 6f 6e 20 61 6e 64 | 20 76 65 6c 6f 63 69 74 |tion and| velocit| |00003f80| 79 20 76 61 72 69 61 62 | 6c 65 73 20 61 72 65 20 |y variab|les are | |00003f90| 75 70 64 61 74 65 64 20 | 61 6e 64 20 63 68 65 63 |updated |and chec| |00003fa0| 6b 65 64 20 66 6f 72 0d | 09 2f 2f 20 62 6f 75 6e |ked for.|.// boun| |00003fb0| 63 69 6e 67 20 65 74 63 | 2e 20 54 68 65 6e 2c 20 |cing etc|. Then, | |00003fc0| 77 65 20 2a 65 72 61 73 | 65 2a 20 28 69 6e 20 74 |we *eras|e* (in t| |00003fd0| 68 65 20 6f 66 66 73 63 | 72 65 65 6e 20 77 6f 72 |he offsc|reen wor| |00003fe0| 6c 64 29 20 74 68 65 20 | 27 6f 6c 64 27 20 73 77 |ld) the |'old' sw| |00003ff0| 61 72 6d 0d 09 2f 2f 20 | 62 79 20 66 69 6c 6c 69 |arm..// |by filli| |00004000| 6e 67 20 74 68 65 20 73 | 77 61 72 6d 27 73 20 62 |ng the s|warm's b| |00004010| 6f 75 6e 64 69 6e 67 20 | 72 65 63 74 61 6e 67 6c |ounding |rectangl| |00004020| 65 20 28 77 68 69 63 68 | 20 77 69 6c 6c 20 76 61 |e (which| will va| |00004030| 72 79 20 66 72 6f 6d 20 | 66 72 61 6d 65 20 74 6f |ry from |frame to| |00004040| 20 66 72 61 6d 65 21 29 | 0d 09 2f 2f 20 77 69 74 | frame!)|..// wit| |00004050| 68 20 74 68 65 20 62 61 | 63 6b 67 72 6f 75 6e 64 |h the ba|ckground| |00004060| 20 63 6f 6c 6f 72 2e 20 | 54 68 65 6e 2c 20 77 65 | color. |Then, we| |00004070| 20 64 72 61 77 20 74 68 | 65 20 27 6e 65 77 27 20 | draw th|e 'new' | |00004080| 73 77 61 72 6d 2e 20 46 | 69 6e 61 6c 6c 79 2c 20 |swarm. F|inally, | |00004090| 77 65 20 75 73 65 0d 09 | 2f 2f 20 74 68 65 20 66 |we use..|// the f| |000040a0| 61 6d 6f 75 73 20 27 43 | 6f 70 79 42 69 74 73 27 |amous 'C|opyBits'| |000040b0| 20 66 75 6e 63 74 69 6f | 6e 20 74 6f 20 6d 6f 76 | functio|n to mov| |000040c0| 65 20 74 68 65 20 63 68 | 61 6e 67 65 64 20 61 72 |e the ch|anged ar| |000040d0| 65 61 73 20 6f 66 20 74 | 68 65 20 6f 66 66 73 63 |eas of t|he offsc| |000040e0| 72 65 65 6e 0d 09 2f 2f | 20 77 6f 72 6c 64 20 74 |reen..//| world t| |000040f0| 6f 20 74 68 65 20 72 65 | 61 6c 20 73 63 72 65 65 |o the re|al scree| |00004100| 6e 20 77 6f 72 6c 64 2e | 20 41 6e 64 20 74 68 61 |n world.| And tha| |00004110| 74 27 73 20 61 6c 6c 2e | 0d 09 0d 09 2f 2f 20 4f |t's all.|....// O| |00004120| 6e 65 20 6d 6f 72 65 20 | 63 6f 6d 6d 65 6e 74 3a |ne more |comment:| |00004130| 20 61 20 6c 6f 74 20 6f | 66 20 74 68 65 20 61 72 | a lot o|f the ar| |00004140| 72 61 79 20 61 63 63 65 | 73 73 65 73 20 63 6f 75 |ray acce|sses cou| |00004150| 6c 64 20 68 61 76 65 20 | 62 65 65 6e 20 6f 70 74 |ld have |been opt| |00004160| 69 6d 69 7a 65 64 0d 09 | 2f 2f 20 74 6f 20 6d 61 |imized..|// to ma| |00004170| 6b 65 20 74 68 65 20 63 | 6f 64 65 20 72 75 6e 20 |ke the c|ode run | |00004180| 66 61 73 74 65 72 2e 20 | 4c 6f 63 61 6c 20 76 61 |faster. |Local va| |00004190| 72 69 61 62 6c 65 73 20 | 63 6f 75 6c 64 20 68 61 |riables |could ha| |000041a0| 76 65 20 62 65 65 6e 20 | 75 73 65 64 20 74 6f 20 |ve been |used to | |000041b0| 61 76 6f 69 64 0d 09 2f | 2f 20 74 68 65 20 70 6f |avoid../|/ the po| |000041c0| 69 6e 74 65 72 20 61 72 | 69 74 68 6d 65 74 69 63 |inter ar|ithmetic| |000041d0| 20 63 61 75 73 65 64 20 | 62 79 20 61 6c 6c 20 74 | caused |by all t| |000041e0| 68 6f 73 65 20 67 6c 6f | 62 61 6c 20 68 61 6e 64 |hose glo|bal hand| |000041f0| 6c 65 73 20 61 6e 64 20 | 61 72 72 61 79 73 2e 0d |les and |arrays..| |00004200| 09 2f 2f 20 54 68 65 20 | 42 6c 6f 63 6b 4d 6f 76 |.// The |BlockMov| |00004210| 65 20 66 75 6e 63 74 69 | 6f 6e 20 63 6f 75 6c 64 |e functi|on could| |00004220| 20 68 61 76 65 20 62 65 | 65 6e 20 63 61 6c 6c 65 | have be|en calle| |00004230| 64 20 74 6f 20 75 70 64 | 61 74 65 73 20 65 6e 74 |d to upd|ates ent| |00004240| 69 72 65 20 61 72 72 61 | 79 73 20 69 6e 0d 09 2f |ire arra|ys in../| |00004250| 2f 20 6f 6e 65 20 73 77 | 65 65 70 2e 0d 09 2f 2f |/ one sw|eep...//| |00004260| 20 48 6f 77 65 76 65 72 | 2c 20 61 6c 6c 20 74 68 | However|, all th| |00004270| 6f 73 65 20 61 63 63 65 | 73 73 65 73 20 74 61 6b |ose acce|sses tak| |00004280| 65 6e 20 74 6f 67 65 74 | 68 65 72 20 73 74 69 6c |en toget|her stil| |00004290| 6c 20 74 61 6b 65 20 75 | 70 20 6f 6e 6c 79 20 61 |l take u|p only a| |000042a0| 20 6e 65 67 6c 69 67 61 | 62 6c 65 20 66 72 61 63 | negliga|ble frac| |000042b0| 74 69 6f 6e 0d 09 2f 2f | 20 6f 66 20 74 68 69 73 |tion..//| of this| |000042c0| 20 66 75 6e 63 74 69 6f | 6e 27 73 20 74 6f 74 61 | functio|n's tota| |000042d0| 6c 20 65 78 65 63 75 74 | 69 6f 6e 20 74 69 6d 65 |l execut|ion time| |000042e0| 2c 20 77 68 65 6e 20 63 | 6f 6d 70 61 72 65 64 20 |, when c|ompared | |000042f0| 74 6f 20 74 68 65 20 63 | 6f 73 74 20 6f 66 0d 09 |to the c|ost of..| |00004300| 2f 2f 20 64 6f 69 6e 67 | 20 74 68 65 20 67 72 61 |// doing| the gra| |00004310| 70 68 69 63 73 2e 20 43 | 6f 70 79 42 69 74 73 20 |phics. C|opyBits | |00004320| 69 73 20 61 6e 20 65 78 | 70 65 6e 73 69 76 65 20 |is an ex|pensive | |00004330| 66 75 6e 63 74 69 6f 6e | 2c 20 61 6e 64 20 66 6f |function|, and fo| |00004340| 72 20 6c 61 72 67 65 20 | 6e 75 6d 62 65 72 73 0d |r large |numbers.| |00004350| 09 2f 2f 20 6f 66 20 42 | 65 65 73 20 74 68 65 20 |.// of B|ees the | |00004360| 64 72 61 77 69 6e 67 20 | 6f 66 20 74 68 65 20 6c |drawing |of the l| |00004370| 69 6e 65 20 73 65 67 6d | 65 6e 74 73 20 74 61 6b |ine segm|ents tak| |00004380| 65 73 20 65 76 65 6e 20 | 6d 6f 72 65 20 74 69 6d |es even |more tim| |00004390| 65 2e 0d 09 2f 2f 20 54 | 68 69 73 20 69 73 20 77 |e...// T|his is w| |000043a0| 68 79 20 49 20 68 61 76 | 65 20 64 65 63 69 64 65 |hy I hav|e decide| |000043b0| 64 20 74 6f 20 72 65 66 | 72 61 69 6e 20 66 72 6f |d to ref|rain fro| |000043c0| 6d 20 6f 70 74 69 6d 69 | 7a 69 6e 67 2e 20 49 74 |m optimi|zing. It| |000043d0| 20 64 6f 65 73 6e 27 74 | 20 6d 61 74 74 65 72 20 | doesn't| matter | |000043e0| 76 65 72 79 0d 09 2f 2f | 20 6d 75 63 68 20 73 70 |very..//| much sp| |000043f0| 65 65 64 77 69 73 65 2c | 20 61 6e 64 20 73 75 63 |eedwise,| and suc| |00004400| 68 20 6f 70 74 69 6d 69 | 7a 61 74 69 6f 6e 73 20 |h optimi|zations | |00004410| 77 6f 75 6c 64 20 6f 6e | 6c 79 20 6f 62 73 63 75 |would on|ly obscu| |00004420| 72 65 20 74 68 65 20 75 | 6e 64 65 72 6c 79 69 6e |re the u|nderlyin| |00004430| 67 20 61 6c 67 6f 72 69 | 74 68 6d 2e 0d 09 0d 4f |g algori|thm....O| |00004440| 53 45 72 72 0d 44 6f 44 | 72 61 77 46 72 61 6d 65 |SErr.DoD|rawFrame| |00004450| 28 48 61 6e 64 6c 65 20 | 73 74 6f 72 61 67 65 2c |(Handle |storage,| |00004460| 20 52 67 6e 48 61 6e 64 | 6c 65 20 62 6c 61 6e 6b | RgnHand|le blank| |00004470| 52 67 6e 2c 20 47 4d 50 | 61 72 61 6d 42 6c 6f 63 |Rgn, GMP|aramBloc| |00004480| 6b 50 74 72 20 70 61 72 | 61 6d 73 29 0d 7b 09 20 |kPtr par|ams).{. | |00004490| 20 20 20 0d 20 20 20 20 | 72 65 67 69 73 74 65 72 | . |register| |000044a0| 20 53 77 61 72 6d 53 74 | 6f 72 61 67 65 50 74 72 | SwarmSt|oragePtr| |000044b0| 20 73 77 61 72 6d 3b 0d | 20 20 20 20 0d 20 20 20 | swarm;.| . | |000044c0| 20 09 2f 2f 20 41 67 61 | 69 6e 2c 20 6c 6f 74 73 | .// Aga|in, lots| |000044d0| 20 6f 66 20 6c 6f 63 61 | 6c 20 76 61 72 69 61 62 | of loca|l variab| |000044e0| 6c 65 73 20 69 6e 20 6f | 72 64 65 72 20 74 6f 20 |les in o|rder to | |000044f0| 61 76 6f 69 64 0d 20 20 | 20 20 09 2f 2f 20 74 6f |avoid. | .// to| |00004500| 6f 20 6d 75 63 68 20 27 | 73 77 61 72 6d 2d 3e 2e |o much '|swarm->.| |00004510| 2e 2e 27 20 73 74 75 66 | 66 2e 0d 20 20 20 20 52 |..' stuf|f.. R| |00004520| 47 42 43 6f 6c 6f 72 20 | 62 65 65 52 47 42 2c 20 |GBColor |beeRGB, | |00004530| 71 75 65 65 6e 52 47 42 | 2c 20 77 68 69 74 65 52 |queenRGB|, whiteR| |00004540| 47 42 2c 20 62 61 63 6b | 52 47 42 3b 0d 20 20 20 |GB, back|RGB;. | |00004550| 20 52 65 63 74 20 6d 6f | 6e 69 74 6f 72 52 65 63 | Rect mo|nitorRec| |00004560| 74 2c 20 2a 73 77 61 72 | 6d 52 65 63 74 2c 20 2a |t, *swar|mRect, *| |00004570| 6f 6c 64 52 65 63 74 3b | 0d 20 20 20 20 69 6e 74 |oldRect;|. int| |00004580| 20 77 69 6e 57 2c 20 77 | 69 6e 48 2c 20 6e 42 65 | winW, w|inH, nBe| |00004590| 65 73 2c 20 62 6f 72 64 | 65 72 3b 0d 20 20 20 20 |es, bord|er;. | |000045a0| 6c 6f 6e 67 20 64 65 6c | 61 79 2c 20 64 75 6d 6d |long del|ay, dumm| |000045b0| 79 3b 09 09 2f 2f 20 27 | 64 75 6d 6d 79 27 20 76 |y;..// '|dummy' v| |000045c0| 61 72 69 61 62 6c 65 20 | 69 73 20 75 6e 75 73 65 |ariable |is unuse| |000045d0| 64 2c 20 62 75 74 20 6e | 65 65 64 65 64 0d 20 20 |d, but n|eeded. | |000045e0| 20 20 09 09 09 09 09 09 | 2f 2f 20 66 6f 72 20 44 | ......|// for D| |000045f0| 65 6c 61 79 20 74 6f 6f | 6c 62 6f 78 20 63 61 6c |elay too|lbox cal| |00004600| 6c 2e 0d 20 20 20 20 0d | 20 20 20 20 09 2f 2f 20 |l.. .| .// | |00004610| 56 61 72 69 61 62 6c 65 | 73 20 75 73 65 64 20 66 |Variable|s used f| |00004620| 6f 72 20 63 61 6c 63 75 | 6c 61 74 69 6e 67 20 74 |or calcu|lating t| |00004630| 68 65 20 73 77 61 72 6d | 27 73 20 62 6f 75 6e 64 |he swarm|'s bound| |00004640| 69 6e 67 20 72 65 63 74 | 61 6e 67 6c 65 2e 0d 20 |ing rect|angle.. | |00004650| 20 20 20 69 6e 74 20 78 | 4d 69 6e 3d 31 30 30 30 | int x|Min=1000| |00004660| 30 2c 20 78 4d 61 78 3d | 2d 31 30 30 30 30 2c 20 |0, xMax=|-10000, | |00004670| 79 4d 69 6e 3d 31 30 30 | 30 30 2c 20 79 4d 61 78 |yMin=100|00, yMax| |00004680| 3d 2d 31 30 30 30 30 3b | 0d 0d 20 20 20 20 47 57 |=-10000;|.. GW| |00004690| 6f 72 6c 64 50 74 72 20 | 63 75 72 72 50 6f 72 74 |orldPtr |currPort| |000046a0| 3b 09 09 2f 2f 20 54 68 | 65 20 27 72 65 61 6c 27 |;..// Th|e 'real'| |000046b0| 20 73 63 72 65 65 6e 20 | 63 6f 6e 73 69 73 74 73 | screen |consists| |000046c0| 20 6f 66 20 74 77 6f 20 | 63 6f 6d 70 6f 6e 65 6e | of two |componen| |000046d0| 74 73 2e 0d 09 47 44 48 | 61 6e 64 6c 65 20 20 63 |ts...GDH|andle c| |000046e0| 75 72 72 44 65 76 3b 09 | 09 2f 2f 20 77 68 69 63 |urrDev;.|.// whic| |000046f0| 68 20 77 65 27 6c 6c 20 | 73 61 76 65 20 69 6e 20 |h we'll |save in | |00004700| 74 68 65 73 65 20 76 61 | 72 69 61 62 6c 65 73 2e |these va|riables.| |00004710| 0d 09 0d 09 09 2f 2f 20 | 54 68 65 20 61 63 74 75 |.....// |The actu| |00004720| 61 6c 20 70 69 78 65 6c | 20 6d 61 70 73 20 6f 66 |al pixel| maps of| |00004730| 20 6f 66 66 73 63 72 65 | 65 6e 20 61 6e 64 20 72 | offscre|en and r| |00004740| 65 61 6c 20 73 63 72 65 | 65 6e 2c 20 72 65 73 70 |eal scre|en, resp| |00004750| 65 63 74 69 76 65 6c 79 | 2e 0d 09 50 69 78 4d 61 |ectively|...PixMa| |00004760| 70 48 61 6e 64 6c 65 20 | 6f 66 66 42 61 73 65 2c |pHandle |offBase,| |00004770| 20 72 65 61 6c 42 61 73 | 65 3b 0d 0d 09 09 2f 2f | realBas|e;....//| |00004780| 20 56 61 72 69 6f 75 73 | 20 72 65 63 74 61 6e 67 | Various| rectang| |00004790| 6c 65 73 2e 2e 2e 3a 2d | 29 0d 09 52 65 63 74 20 |les...:-|)..Rect | |000047a0| 75 6e 69 6f 6e 52 65 63 | 74 2c 20 74 61 72 67 65 |unionRec|t, targe| |000047b0| 74 52 65 63 74 2c 20 68 | 65 6c 70 52 65 63 74 2c |tRect, h|elpRect,| |000047c0| 20 70 69 78 52 65 63 74 | 2c 20 73 63 72 65 65 6e | pixRect|, screen| |000047d0| 52 65 63 74 2c 20 74 6d | 70 52 65 63 74 3b 0d 09 |Rect, tm|pRect;..| |000047e0| 0d 09 09 2f 2f 20 44 69 | 73 74 61 6e 63 65 73 20 |...// Di|stances | |000047f0| 66 72 6f 6d 20 61 20 42 | 65 65 20 74 6f 20 74 68 |from a B|ee to th| |00004800| 65 20 51 75 65 65 6e 2e | 0d 20 20 20 20 69 6e 74 |e Queen.|. int| |00004810| 20 64 78 2c 20 64 79 2c | 20 64 69 73 74 61 6e 63 | dx, dy,| distanc| |00004820| 65 3b 09 09 09 0d 0d 09 | 09 2f 2f 20 42 65 65 20 |e;......|.// Bee | |00004830| 63 6f 75 6e 74 65 72 20 | 66 6f 72 20 6c 6f 6f 70 |counter |for loop| |00004840| 73 2e 0d 20 20 20 20 72 | 65 67 69 73 74 65 72 20 |s.. r|egister | |00004850| 69 6e 74 20 62 3b 0d 20 | 20 20 20 0d 09 09 2f 2f |int b;. | ...//| |00004860| 20 73 74 6f 72 61 67 65 | 20 77 61 73 20 61 6c 72 | storage| was alr| |00004870| 65 61 64 79 20 6c 6f 63 | 6b 65 64 20 69 6e 20 44 |eady loc|ked in D| |00004880| 6f 49 6e 69 74 69 61 6c | 69 7a 65 2c 20 73 6f 20 |oInitial|ize, so | |00004890| 74 68 69 73 20 69 73 20 | 73 61 66 65 2e 0d 20 20 |this is |safe.. | |000048a0| 20 20 73 77 61 72 6d 20 | 3d 20 28 53 77 61 72 6d | swarm |= (Swarm| |000048b0| 53 74 6f 72 61 67 65 50 | 74 72 29 20 2a 73 74 6f |StorageP|tr) *sto| |000048c0| 72 61 67 65 3b 0d 20 20 | 20 20 0d 20 20 20 20 6e |rage;. | . n| |000048d0| 42 65 65 73 20 3d 20 73 | 77 61 72 6d 2d 3e 6e 42 |Bees = s|warm->nB| |000048e0| 65 65 73 3b 0d 20 20 20 | 20 64 65 6c 61 79 20 3d |ees;. | delay =| |000048f0| 20 73 77 61 72 6d 2d 3e | 64 65 6c 61 79 3b 0d 0d | swarm->|delay;..| |00004900| 20 20 20 20 09 2f 2f 20 | 49 66 20 77 65 20 61 72 | .// |If we ar| |00004910| 65 20 69 6e 20 44 65 6d | 6f 20 6d 6f 64 65 2c 20 |e in Dem|o mode, | |00004920| 72 65 72 65 61 64 20 74 | 68 65 20 6e 42 65 65 73 |reread t|he nBees| |00004930| 20 61 6e 64 20 64 65 6c | 61 79 20 76 61 6c 75 65 | and del|ay value| |00004940| 73 20 2d 2d 20 74 68 65 | 20 75 73 65 72 20 6d 61 |s -- the| user ma| |00004950| 79 20 68 61 76 65 0d 20 | 20 20 20 09 2f 2f 20 63 |y have. | .// c| |00004960| 68 61 6e 67 65 64 20 74 | 68 65 6d 20 64 79 6e 61 |hanged t|hem dyna| |00004970| 6d 69 63 61 6c 6c 79 2e | 0d 20 20 20 20 69 66 20 |mically.|. if | |00004980| 28 73 77 61 72 6d 2d 3e | 64 65 6d 6f 4d 6f 64 65 |(swarm->|demoMode| |00004990| 29 0d 20 20 20 20 7b 0d | 20 20 20 20 09 69 66 20 |). {.| .if | |000049a0| 28 6e 42 65 65 73 20 21 | 3d 20 70 61 72 61 6d 73 |(nBees !|= params| |000049b0| 2d 3e 63 6f 6e 74 72 6f | 6c 56 61 6c 75 65 73 5b |->contro|lValues[| |000049c0| 30 5d 29 0d 20 20 20 20 | 09 20 20 20 20 6e 42 65 |0]). |. nBe| |000049d0| 65 73 20 3d 20 73 77 61 | 72 6d 2d 3e 6e 42 65 65 |es = swa|rm->nBee| |000049e0| 73 20 3d 20 70 61 72 61 | 6d 73 2d 3e 63 6f 6e 74 |s = para|ms->cont| |000049f0| 72 6f 6c 56 61 6c 75 65 | 73 5b 30 5d 3b 0d 0d 20 |rolValue|s[0];.. | |00004a00| 20 20 20 09 69 66 20 28 | 64 65 6c 61 79 20 21 3d | .if (|delay !=| |00004a10| 20 70 61 72 61 6d 73 2d | 3e 63 6f 6e 74 72 6f 6c | params-|>control| |00004a20| 56 61 6c 75 65 73 5b 31 | 5d 29 20 0d 09 09 20 20 |Values[1|]) ... | |00004a30| 20 20 64 65 6c 61 79 20 | 3d 20 73 77 61 72 6d 2d | delay |= swarm-| |00004a40| 3e 64 65 6c 61 79 20 3d | 20 28 6c 6f 6e 67 29 31 |>delay =| (long)1| |00004a50| 30 20 2d 20 28 32 2a 70 | 61 72 61 6d 73 2d 3e 63 |0 - (2*p|arams->c| |00004a60| 6f 6e 74 72 6f 6c 56 61 | 6c 75 65 73 5b 31 5d 20 |ontrolVa|lues[1] | |00004a70| 2f 20 32 30 29 3b 0d 0d | 09 7d 0d 20 20 20 20 09 |/ 20);..|.}. .| |00004a80| 2f 2f 20 54 68 65 20 6e | 65 78 74 20 74 68 69 6e |// The n|ext thin| |00004a90| 67 20 74 6f 20 64 6f 20 | 69 73 20 74 6f 20 63 68 |g to do |is to ch| |00004aa0| 65 63 6b 20 66 6f 72 20 | 64 65 6c 61 79 2e 20 54 |eck for |delay. T| |00004ab0| 68 69 73 20 63 61 6e 20 | 62 65 20 64 6f 6e 65 0d |his can |be done.| |00004ac0| 20 20 20 20 09 2f 2f 20 | 6e 61 69 76 65 6c 79 20 | .// |naively | |00004ad0| 62 79 20 73 69 6d 70 6c | 79 20 75 73 69 6e 67 20 |by simpl|y using | |00004ae0| 74 68 65 20 44 65 6c 61 | 79 20 73 79 73 74 65 6d |the Dela|y system| |00004af0| 20 66 75 6e 63 74 69 6f | 6e 20 28 77 69 74 68 20 | functio|n (with | |00004b00| 27 73 77 61 72 6d 2d 3e | 64 65 6c 61 79 27 20 61 |'swarm->|delay' a| |00004b10| 73 0d 20 20 20 20 09 2f | 2f 20 70 61 72 61 6d 65 |s. ./|/ parame| |00004b20| 74 65 72 29 2c 20 62 75 | 74 20 74 68 61 74 20 77 |ter), bu|t that w| |00004b30| 6f 75 6c 64 20 6d 65 61 | 6e 20 74 68 61 74 20 77 |ould mea|n that w| |00004b40| 65 20 77 6f 75 6c 64 20 | 73 69 6d 70 6c 79 20 73 |e would |simply s| |00004b50| 70 65 6e 64 20 74 68 6f | 73 65 0d 09 09 2f 2f 20 |pend tho|se...// | |00004b60| 74 69 63 6b 73 20 2a 64 | 6f 69 6e 67 20 6e 6f 74 |ticks *d|oing not| |00004b70| 68 69 6e 67 2a 20 2d 2d | 20 61 6e 64 20 6e 6f 74 |hing* --| and not| |00004b80| 20 61 6c 6c 6f 77 69 6e | 67 20 61 6e 79 74 68 69 | allowin|g anythi| |00004b90| 6e 67 20 65 6c 73 65 20 | 74 6f 20 64 6f 20 61 6e |ng else |to do an| |00004ba0| 79 74 68 69 6e 67 0d 09 | 09 2f 2f 20 65 69 74 68 |ything..|.// eith| |00004bb0| 65 72 2e 20 54 68 61 74 | 27 73 20 77 68 79 20 77 |er. That|'s why w| |00004bc0| 65 20 64 6f 20 69 74 20 | 64 69 66 66 65 72 65 6e |e do it |differen| |00004bd0| 74 6c 79 3a 20 69 66 20 | 74 68 65 20 64 65 6c 61 |tly: if |the dela| |00004be0| 79 20 68 61 73 20 6e 6f | 74 20 70 61 73 73 65 64 |y has no|t passed| |00004bf0| 20 79 65 74 2c 0d 09 09 | 2f 2f 20 77 65 20 73 69 | yet,...|// we si| |00004c00| 6d 70 6c 79 20 65 78 69 | 74 20 66 72 6f 6d 20 74 |mply exi|t from t| |00004c10| 68 69 73 20 66 75 6e 63 | 74 69 6f 6e 20 61 74 20 |his func|tion at | |00004c20| 6f 6e 63 65 2c 20 61 6e | 64 20 77 61 69 74 20 75 |once, an|d wait u| |00004c30| 6e 74 69 6c 20 77 65 20 | 61 72 65 20 63 61 6c 6c |ntil we |are call| |00004c40| 65 64 20 61 67 61 69 6e | 2e 0d 09 09 2f 2f 20 54 |ed again|....// T| |00004c50| 68 61 74 20 77 61 79 2c | 20 61 6c 6d 6f 73 74 20 |hat way,| almost | |00004c60| 61 6c 6c 20 74 68 65 20 | 64 65 6c 61 79 20 74 69 |all the |delay ti| |00004c70| 6d 65 20 69 73 20 67 69 | 76 65 6e 20 74 6f 20 74 |me is gi|ven to t| |00004c80| 68 65 20 41 66 74 65 72 | 20 44 61 72 6b 20 70 61 |he After| Dark pa| |00004c90| 72 65 6e 74 0d 09 09 2f | 2f 20 70 72 6f 63 65 73 |rent.../|/ proces| |00004ca0| 73 20 77 68 69 63 68 20 | 63 61 6e 20 74 68 65 6e |s which |can then| |00004cb0| 20 70 72 65 73 75 6d 65 | 61 62 6c 79 20 75 73 65 | presume|ably use| |00004cc0| 20 69 74 20 74 6f 20 63 | 68 65 63 6b 20 66 6f 72 | it to c|heck for| |00004cd0| 20 73 79 73 74 65 6d 20 | 61 63 74 69 76 69 74 79 | system |activity| |00004ce0| 20 65 74 63 2e 0d 09 09 | 0d 09 69 66 20 28 64 65 | etc....|..if (de| |00004cf0| 6c 61 79 20 21 3d 20 30 | 29 0d 09 09 69 66 20 28 |lay != 0|)...if (| |00004d00| 54 69 63 6b 73 20 3c 20 | 73 77 61 72 6d 2d 3e 73 |Ticks < |swarm->s| |00004d10| 74 61 72 74 44 72 61 77 | 69 6e 67 29 0d 09 09 09 |tartDraw|ing)....| |00004d20| 72 65 74 75 72 6e 20 6e | 6f 45 72 72 3b 0d 09 09 |return n|oErr;...| |00004d30| 65 6c 73 65 0d 09 09 09 | 73 77 61 72 6d 2d 3e 73 |else....|swarm->s| |00004d40| 74 61 72 74 44 72 61 77 | 69 6e 67 20 3d 20 54 69 |tartDraw|ing = Ti| |00004d50| 63 6b 73 20 2b 20 64 65 | 6c 61 79 3b 0d 09 0d 09 |cks + de|lay;....| |00004d60| 09 2f 2f 20 49 6e 69 74 | 69 61 6c 69 7a 65 20 74 |.// Init|ialize t| |00004d70| 68 65 20 6f 74 68 65 72 | 20 6c 6f 63 61 6c 20 76 |he other| local v| |00004d80| 61 72 69 61 62 6c 65 73 | 20 66 72 6f 6d 20 74 68 |ariables| from th| |00004d90| 65 69 72 20 73 77 61 72 | 6d 20 63 6f 75 6e 74 65 |eir swar|m counte| |00004da0| 72 70 61 72 74 73 2e 0d | 09 6d 6f 6e 69 74 6f 72 |rparts..|.monitor| |00004db0| 52 65 63 74 20 3d 20 73 | 77 61 72 6d 2d 3e 6d 6f |Rect = s|warm->mo| |00004dc0| 6e 69 74 6f 72 52 65 63 | 74 3b 0d 09 77 69 6e 57 |nitorRec|t;..winW| |00004dd0| 20 20 20 3d 20 73 77 61 | 72 6d 2d 3e 77 69 6e 57 | = swa|rm->winW| |00004de0| 3b 0d 09 77 69 6e 48 20 | 20 20 3d 20 73 77 61 72 |;..winH | = swar| |00004df0| 6d 2d 3e 77 69 6e 48 3b | 0d 09 62 6f 72 64 65 72 |m->winH;|..border| |00004e00| 20 3d 20 73 77 61 72 6d | 2d 3e 62 6f 72 64 65 72 | = swarm|->border| |00004e10| 3b 0d 09 0d 09 62 61 63 | 6b 52 47 42 20 20 3d 20 |;....bac|kRGB = | |00004e20| 73 77 61 72 6d 2d 3e 62 | 61 63 6b 52 47 42 3b 0d |swarm->b|ackRGB;.| |00004e30| 09 77 68 69 74 65 52 47 | 42 20 3d 20 73 77 61 72 |.whiteRG|B = swar| |00004e40| 6d 2d 3e 77 68 69 74 65 | 52 47 42 3b 0d 09 71 75 |m->white|RGB;..qu| |00004e50| 65 65 6e 52 47 42 20 3d | 20 73 77 61 72 6d 2d 3e |eenRGB =| swarm->| |00004e60| 71 75 65 65 6e 52 47 42 | 3b 0d 09 62 65 65 52 47 |queenRGB|;..beeRG| |00004e70| 42 20 20 20 3d 20 73 77 | 61 72 6d 2d 3e 62 65 65 |B = sw|arm->bee| |00004e80| 52 47 42 3b 0d 09 0d 20 | 20 20 20 73 77 61 72 6d |RGB;... | swarm| |00004e90| 52 65 63 74 20 3d 20 26 | 73 77 61 72 6d 2d 3e 73 |Rect = &|swarm->s| |00004ea0| 77 61 72 6d 52 65 63 74 | 3b 0d 20 20 20 20 6f 6c |warmRect|;. ol| |00004eb0| 64 52 65 63 74 20 20 20 | 3d 20 26 73 77 61 72 6d |dRect |= &swarm| |00004ec0| 2d 3e 6f 6c 64 52 65 63 | 74 3b 0d 20 20 20 20 0d |->oldRec|t;. .| |00004ed0| 20 20 20 20 09 2f 2f 20 | 41 67 65 20 74 68 65 20 | .// |Age the | |00004ee0| 73 77 61 72 6d 20 62 6f | 75 64 69 6e 67 20 72 65 |swarm bo|uding re| |00004ef0| 63 74 61 6e 67 6c 65 2e | 0d 20 20 20 20 2a 6f 6c |ctangle.|. *ol| |00004f00| 64 52 65 63 74 20 3d 20 | 2a 73 77 61 72 6d 52 65 |dRect = |*swarmRe| |00004f10| 63 74 3b 0d 20 20 20 20 | 0d 09 09 2f 2f 20 46 69 |ct;. |...// Fi| |00004f20| 72 73 74 2c 20 77 65 20 | 64 6f 20 74 68 65 20 51 |rst, we |do the Q| |00004f30| 75 65 65 6e 20 53 74 75 | 66 66 3a 0d 0d 20 20 20 |ueen Stu|ff:.. | |00004f40| 20 09 2f 2f 20 41 67 65 | 20 74 68 65 20 70 6f 73 | .// Age| the pos| |00004f50| 69 74 69 6f 6e 20 61 72 | 72 61 79 73 2e 20 0d 20 |ition ar|rays. . | |00004f60| 20 20 20 51 58 28 31 29 | 20 3d 20 51 58 28 30 29 | QX(1)| = QX(0)| |00004f70| 3b 0d 20 20 20 20 51 59 | 28 31 29 20 3d 20 51 59 |;. QY|(1) = QY| |00004f80| 28 30 29 3b 0d 0d 20 20 | 20 20 09 2f 2f 20 41 63 |(0);.. | .// Ac| |00004f90| 63 65 6c 65 72 61 74 65 | 2e 0d 20 20 20 20 51 58 |celerate|.. QX| |00004fa0| 56 20 2b 3d 20 52 41 4e | 44 28 73 77 61 72 6d 2d |V += RAN|D(swarm-| |00004fb0| 3e 6d 61 78 51 75 65 65 | 6e 41 63 63 29 3b 0d 20 |>maxQuee|nAcc);. | |00004fc0| 20 20 20 51 59 56 20 2b | 3d 20 52 41 4e 44 28 73 | QYV +|= RAND(s| |00004fd0| 77 61 72 6d 2d 3e 6d 61 | 78 51 75 65 65 6e 41 63 |warm->ma|xQueenAc| |00004fe0| 63 29 3b 0d 0d 20 20 20 | 20 09 2f 2f 20 53 70 65 |c);.. | .// Spe| |00004ff0| 65 64 20 6c 69 6d 69 74 | 20 63 68 65 63 6b 73 2e |ed limit| checks.| |00005000| 0d 20 20 20 20 69 66 20 | 28 51 58 56 20 3e 20 73 |. if |(QXV > s| |00005010| 77 61 72 6d 2d 3e 6d 61 | 78 51 75 65 65 6e 56 65 |warm->ma|xQueenVe| |00005020| 6c 29 0d 20 20 20 20 20 | 20 20 20 51 58 56 20 3d |l). | QXV =| |00005030| 20 73 77 61 72 6d 2d 3e | 6d 61 78 51 75 65 65 6e | swarm->|maxQueen| |00005040| 56 65 6c 3b 0d 20 20 20 | 20 65 6c 73 65 20 0d 20 |Vel;. | else . | |00005050| 20 20 20 09 69 66 20 28 | 51 58 56 20 3c 20 2d 73 | .if (|QXV < -s| |00005060| 77 61 72 6d 2d 3e 6d 61 | 78 51 75 65 65 6e 56 65 |warm->ma|xQueenVe| |00005070| 6c 29 0d 20 20 20 20 20 | 20 20 20 09 51 58 56 20 |l). | .QXV | |00005080| 3d 20 2d 73 77 61 72 6d | 2d 3e 6d 61 78 51 75 65 |= -swarm|->maxQue| |00005090| 65 6e 56 65 6c 3b 0d 20 | 20 20 20 69 66 20 28 51 |enVel;. | if (Q| |000050a0| 59 56 20 3e 20 73 77 61 | 72 6d 2d 3e 6d 61 78 51 |YV > swa|rm->maxQ| |000050b0| 75 65 65 6e 56 65 6c 29 | 0d 20 20 20 20 20 20 20 |ueenVel)|. | |000050c0| 20 51 59 56 20 3d 20 73 | 77 61 72 6d 2d 3e 6d 61 | QYV = s|warm->ma| |000050d0| 78 51 75 65 65 6e 56 65 | 6c 3b 0d 20 20 20 20 65 |xQueenVe|l;. e| |000050e0| 6c 73 65 0d 20 20 20 20 | 09 69 66 20 28 51 59 56 |lse. |.if (QYV| |000050f0| 20 3c 20 2d 73 77 61 72 | 6d 2d 3e 6d 61 78 51 75 | < -swar|m->maxQu| |00005100| 65 65 6e 56 65 6c 29 0d | 20 20 20 20 20 20 20 20 |eenVel).| | |00005110| 09 51 59 56 20 3d 20 2d | 73 77 61 72 6d 2d 3e 6d |.QYV = -|swarm->m| |00005120| 61 78 51 75 65 65 6e 56 | 65 6c 3b 0d 0d 20 20 20 |axQueenV|el;.. | |00005130| 20 09 2f 2f 20 46 69 6c | 6c 20 6e 65 77 20 27 63 | .// Fil|l new 'c| |00005140| 75 72 72 65 6e 74 27 20 | 70 6f 73 69 74 69 6f 6e |urrent' |position| |00005150| 73 2e 0d 20 20 20 20 51 | 58 28 30 29 20 3d 20 51 |s.. Q|X(0) = Q| |00005160| 58 28 31 29 20 2b 20 51 | 58 56 3b 0d 20 20 20 20 |X(1) + Q|XV;. | |00005170| 51 59 28 30 29 20 3d 20 | 51 59 28 31 29 20 2b 20 |QY(0) = |QY(1) + | |00005180| 51 59 56 3b 0d 0d 20 20 | 20 20 09 2f 2f 20 42 6f |QYV;.. | .// Bo| |00005190| 75 6e 63 65 20 43 68 65 | 63 6b 73 2e 0d 20 20 20 |unce Che|cks.. | |000051a0| 20 69 66 20 28 28 51 58 | 28 30 29 20 3c 20 62 6f | if ((QX|(0) < bo| |000051b0| 72 64 65 72 29 20 7c 7c | 20 28 51 58 28 30 29 20 |rder) ||| (QX(0) | |000051c0| 3e 20 77 69 6e 57 20 2d | 20 62 6f 72 64 65 72 20 |> winW -| border | |000051d0| 2d 20 31 29 29 0d 20 20 | 20 20 7b 0d 20 20 20 20 |- 1)). | {. | |000051e0| 09 09 2f 2f 20 54 68 65 | 73 65 20 74 77 6f 20 73 |..// The|se two s| |000051f0| 74 61 74 65 6d 65 6e 74 | 73 20 28 61 6e 64 20 61 |tatement|s (and a| |00005200| 6c 6c 20 73 69 6d 69 6c | 61 72 20 6f 6e 65 73 20 |ll simil|ar ones | |00005210| 66 75 72 74 68 65 72 20 | 6f 6e 29 0d 20 20 20 20 |further |on). | |00005220| 09 09 2f 2f 20 63 61 75 | 73 65 20 61 20 73 77 61 |..// cau|se a swa| |00005230| 72 6d 20 65 6c 65 6d 65 | 6e 74 20 74 6f 20 27 62 |rm eleme|nt to 'b| |00005240| 6f 75 6e 63 65 20 6f 66 | 66 27 20 61 63 63 6f 72 |ounce of|f' accor| |00005250| 64 69 6e 67 20 74 6f 20 | 61 0d 20 20 20 20 09 09 |ding to |a. ..| |00005260| 2f 2f 20 22 61 6e 67 6c | 65 20 6f 66 20 65 6e 74 |// "angl|e of ent| |00005270| 72 79 20 69 73 20 61 6e | 67 6c 65 20 6f 66 20 65 |ry is an|gle of e| |00005280| 78 69 74 22 20 72 75 6c | 65 2e 20 49 74 20 6c 6f |xit" rul|e. It lo| |00005290| 6f 6b 73 20 6d 75 63 68 | 20 6d 6f 72 65 0d 20 20 |oks much| more. | |000052a0| 20 20 09 09 2f 2f 20 63 | 72 79 70 74 69 63 20 74 | ..// c|ryptic t| |000052b0| 68 61 6e 20 69 74 20 72 | 65 61 6c 6c 79 20 69 73 |han it r|eally is| |000052c0| 2e 20 54 72 75 73 74 20 | 6d 65 2e 0d 20 20 20 20 |. Trust |me.. | |000052d0| 20 20 20 20 51 58 56 20 | 3d 20 2d 51 58 56 3b 0d | QXV |= -QXV;.| |000052e0| 20 20 20 20 20 20 20 20 | 51 58 28 30 29 20 2b 3d | |QX(0) +=| |000052f0| 20 51 58 56 20 3c 3c 20 | 31 3b 0d 20 20 20 20 7d | QXV << |1;. }| |00005300| 0d 20 20 20 20 69 66 20 | 28 28 51 59 28 30 29 20 |. if |((QY(0) | |00005310| 3c 20 62 6f 72 64 65 72 | 29 20 7c 7c 20 28 51 59 |< border|) || (QY| |00005320| 28 30 29 20 3e 20 77 69 | 6e 48 20 2d 20 62 6f 72 |(0) > wi|nH - bor| |00005330| 64 65 72 20 2d 20 31 29 | 29 0d 20 20 20 20 7b 0d |der - 1)|). {.| |00005340| 20 20 20 20 20 20 20 20 | 51 59 56 20 3d 20 2d 51 | |QYV = -Q| |00005350| 59 56 3b 0d 20 20 20 20 | 20 20 20 20 51 59 28 30 |YV;. | QY(0| |00005360| 29 20 2b 3d 20 51 59 56 | 20 3c 3c 20 31 3b 0d 20 |) += QYV| << 1;. | |00005370| 20 20 20 7d 0d 20 20 20 | 20 0d 20 09 09 2f 2f 20 | }. | . ..// | |00005380| 49 66 20 77 65 20 61 72 | 65 20 69 6e 20 64 65 6d |If we ar|e in dem| |00005390| 6f 20 4d 6f 64 65 2c 20 | 77 65 20 77 61 6e 74 20 |o Mode, |we want | |000053a0| 74 68 65 20 51 75 65 65 | 6e 20 74 6f 20 27 62 6f |the Quee|n to 'bo| |000053b0| 75 6e 63 65 27 20 6f 66 | 66 0d 20 09 09 2f 2f 20 |unce' of|f. ..// | |000053c0| 74 68 65 20 64 65 6d 6f | 52 65 63 74 20 61 73 20 |the demo|Rect as | |000053d0| 77 65 6c 6c 2e 20 54 68 | 69 73 20 74 61 6b 65 73 |well. Th|is takes| |000053e0| 20 73 6f 6d 65 20 68 61 | 69 72 79 20 61 64 64 69 | some ha|iry addi| |000053f0| 74 69 6f 6e 61 6c 20 74 | 65 73 74 69 6e 67 20 3a |tional t|esting :| |00005400| 2d 29 0d 20 20 20 20 0d | 20 20 20 20 09 2f 2f 20 |-). .| .// | |00005410| 57 69 74 68 6f 75 74 20 | 74 68 65 73 65 20 6d 61 |Without |these ma| |00005420| 63 72 6f 27 73 20 27 68 | 61 69 72 79 27 20 77 6f |cro's 'h|airy' wo| |00005430| 75 6c 64 20 62 65 63 6f | 6d 65 20 27 62 6c 6f 6f |uld beco|me 'bloo| |00005440| 64 79 20 69 6e 63 6f 6d | 70 72 65 68 65 6e 73 69 |dy incom|prehensi| |00005450| 62 6c 65 27 2e 0d 20 23 | 64 65 66 69 6e 65 20 44 |ble'.. #|define D| |00005460| 4c 20 28 70 61 72 61 6d | 73 2d 3e 64 65 6d 6f 52 |L (param|s->demoR| |00005470| 65 63 74 2e 6c 65 66 74 | 20 2d 20 62 6f 72 64 65 |ect.left| - borde| |00005480| 72 2f 32 29 0d 20 23 64 | 65 66 69 6e 65 20 44 52 |r/2). #d|efine DR| |00005490| 20 28 70 61 72 61 6d 73 | 2d 3e 64 65 6d 6f 52 65 | (params|->demoRe| |000054a0| 63 74 2e 72 69 67 68 74 | 20 2b 20 62 6f 72 64 65 |ct.right| + borde| |000054b0| 72 2f 32 29 0d 20 23 64 | 65 66 69 6e 65 20 44 54 |r/2). #d|efine DT| |000054c0| 20 28 70 61 72 61 6d 73 | 2d 3e 64 65 6d 6f 52 65 | (params|->demoRe| |000054d0| 63 74 2e 74 6f 70 20 2d | 20 62 6f 72 64 65 72 2f |ct.top -| border/| |000054e0| 32 29 0d 20 23 64 65 66 | 69 6e 65 20 44 42 20 28 |2). #def|ine DB (| |000054f0| 70 61 72 61 6d 73 2d 3e | 64 65 6d 6f 52 65 63 74 |params->|demoRect| |00005500| 2e 62 6f 74 74 6f 6d 20 | 2b 20 62 6f 72 64 65 72 |.bottom |+ border| |00005510| 2f 32 29 0d 20 0d 20 09 | 09 2f 2f 20 54 68 65 20 |/2). . .|.// The | |00005520| 61 63 74 75 61 6c 20 74 | 65 73 74 73 2e 0d 20 20 |actual t|ests.. | |00005530| 20 20 69 66 20 28 21 45 | 6d 70 74 79 52 65 63 74 | if (!E|mptyRect| |00005540| 28 26 70 61 72 61 6d 73 | 2d 3e 64 65 6d 6f 52 65 |(¶ms|->demoRe| |00005550| 63 74 29 29 0d 20 20 20 | 20 7b 0d 20 20 20 20 20 |ct)). | {. | |00005560| 09 69 66 20 28 28 51 58 | 28 30 29 20 3c 20 44 52 |.if ((QX|(0) < DR| |00005570| 29 20 26 26 20 28 51 58 | 28 30 29 20 3e 20 44 4c |) && (QX|(0) > DL| |00005580| 29 20 26 26 20 28 51 59 | 28 30 29 20 3c 20 44 42 |) && (QY|(0) < DB| |00005590| 29 20 26 26 20 28 51 59 | 28 30 29 20 3e 20 44 54 |) && (QY|(0) > DT| |000055a0| 29 29 0d 20 20 20 20 09 | 7b 0d 20 20 20 20 09 09 |)). .|{. ..| |000055b0| 69 66 20 28 28 51 58 28 | 31 29 20 3c 3d 20 44 4c |if ((QX(|1) <= DL| |000055c0| 29 20 7c 7c 20 28 51 58 | 28 31 29 20 3e 3d 20 44 |) || (QX|(1) >= D| |000055d0| 52 29 29 0d 20 20 20 20 | 09 09 7b 0d 20 20 20 20 |R)). |..{. | |000055e0| 09 09 09 51 58 56 20 3d | 20 2d 51 58 56 3b 0d 20 |...QXV =| -QXV;. | |000055f0| 20 20 20 20 20 20 20 20 | 09 09 51 58 28 30 29 20 | |..QX(0) | |00005600| 2b 3d 20 51 58 56 20 3c | 3c 20 31 3b 0d 20 20 20 |+= QXV <|< 1;. | |00005610| 20 20 20 20 20 20 09 7d | 0d 20 20 20 20 20 20 20 | .}|. | |00005620| 20 20 09 69 66 20 28 28 | 51 59 28 31 29 20 3c 3d | .if ((|QY(1) <=| |00005630| 20 44 54 29 20 7c 7c 20 | 28 51 59 28 31 29 20 3e | DT) || |(QY(1) >| |00005640| 3d 20 44 42 29 29 0d 20 | 20 20 20 20 20 20 20 20 |= DB)). | | |00005650| 09 7b 0d 20 20 20 20 09 | 09 09 51 59 56 20 3d 20 |.{. .|..QYV = | |00005660| 2d 51 59 56 3b 0d 20 20 | 20 20 20 20 20 20 20 09 |-QYV;. | .| |00005670| 09 51 59 28 30 29 20 2b | 3d 20 51 59 56 20 3c 3c |.QY(0) +|= QYV <<| |00005680| 20 31 3b 0d 20 20 20 20 | 09 09 7d 0d 20 20 20 20 | 1;. |..}. | |00005690| 09 7d 0d 20 20 20 09 7d | 0d 20 20 20 20 20 20 20 |.}. .}|. | |000056a0| 20 0d 20 20 20 20 20 20 | 20 20 2f 2f 20 4b 65 65 | . | // Kee| |000056b0| 70 20 74 72 61 63 6b 20 | 6f 66 20 74 68 65 20 6d |p track |of the m| |000056c0| 69 6e 69 6d 61 6c 20 62 | 6f 75 64 69 6e 67 20 72 |inimal b|ouding r| |000056d0| 65 63 74 20 6f 66 20 74 | 68 65 20 73 77 61 72 6d |ect of t|he swarm| |000056e0| 20 73 6f 20 66 61 72 2e | 0d 20 20 20 20 73 65 74 | so far.|. set| |000056f0| 6d 69 6e 28 51 58 28 30 | 29 2c 20 78 4d 69 6e 29 |min(QX(0|), xMin)| |00005700| 3b 0d 20 20 20 20 73 65 | 74 6d 69 6e 28 51 59 28 |;. se|tmin(QY(| |00005710| 30 29 2c 20 79 4d 69 6e | 29 3b 0d 09 73 65 74 6d |0), yMin|);..setm| |00005720| 61 78 28 51 58 28 30 29 | 2c 20 78 4d 61 78 29 3b |ax(QX(0)|, xMax);| |00005730| 0d 20 20 20 20 73 65 74 | 6d 61 78 28 51 59 28 30 |. set|max(QY(0| |00005740| 29 2c 20 79 4d 61 78 29 | 3b 0d 0d 09 73 65 74 6d |), yMax)|;...setm| |00005750| 69 6e 28 51 58 28 31 29 | 2c 20 78 4d 69 6e 29 3b |in(QX(1)|, xMin);| |00005760| 0d 20 20 20 20 73 65 74 | 6d 69 6e 28 51 59 28 31 |. set|min(QY(1| |00005770| 29 2c 20 79 4d 69 6e 29 | 3b 0d 09 73 65 74 6d 61 |), yMin)|;..setma| |00005780| 78 28 51 58 28 31 29 2c | 20 78 4d 61 78 29 3b 0d |x(QX(1),| xMax);.| |00005790| 20 20 20 20 73 65 74 6d | 61 78 28 51 59 28 31 29 | setm|ax(QY(1)| |000057a0| 2c 20 79 4d 61 78 29 3b | 0d 20 20 20 20 0d 20 20 |, yMax);|. . | |000057b0| 20 0d 20 20 20 09 09 2f | 2f 20 4e 6f 77 20 77 65 | . ../|/ Now we| |000057c0| 20 67 65 74 20 74 6f 20 | 74 68 65 20 42 65 65 20 | get to |the Bee | |000057d0| 73 74 75 66 66 2c 20 77 | 68 69 63 68 20 69 73 20 |stuff, w|hich is | |000057e0| 62 61 73 69 63 61 6c 6c | 79 0d 20 20 20 09 09 2f |basicall|y. ../| |000057f0| 2f 20 74 68 65 20 73 61 | 6d 65 2c 20 65 78 63 65 |/ the sa|me, exce| |00005800| 70 74 20 74 68 61 74 20 | 28 61 29 20 42 65 65 73 |pt that |(a) Bees| |00005810| 20 64 6f 20 2a 6e 6f 74 | 2a 20 62 6f 75 6e 63 65 | do *not|* bounce| |00005820| 20 6f 66 66 20 77 61 6c | 6c 73 20 6f 72 0d 20 20 | off wal|ls or. | |00005830| 20 09 09 2f 2f 20 64 65 | 6d 6f 52 65 63 74 73 2c | ..// de|moRects,| |00005840| 20 61 6e 64 20 28 62 29 | 20 42 65 65 73 20 77 69 | and (b)| Bees wi| |00005850| 6c 6c 20 74 72 79 20 74 | 6f 20 27 66 6f 6c 6c 6f |ll try t|o 'follo| |00005860| 77 27 20 74 68 65 20 51 | 75 65 65 6e 2e 0d 20 20 |w' the Q|ueen.. | |00005870| 20 09 09 20 0d 20 20 20 | 0d 20 20 20 20 09 2f 2f | .. . |. .//| |00005880| 20 46 69 72 73 74 2c 20 | 64 6f 6e 27 74 20 65 76 | First, |don't ev| |00005890| 65 72 20 6c 65 74 20 74 | 68 69 6e 67 73 20 73 65 |er let t|hings se| |000058a0| 74 74 6c 65 20 64 6f 77 | 6e 2e 20 0d 20 20 20 20 |ttle dow|n. . | |000058b0| 69 66 20 28 6e 42 65 65 | 73 20 3e 20 30 29 20 20 |if (nBee|s > 0) | |000058c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 2f 2f 20 | | // | |000058d0| 41 76 6f 69 64 20 6c 61 | 74 65 72 20 64 69 76 69 |Avoid la|ter divi| |000058e0| 73 69 6f 6e 20 62 79 20 | 30 21 0d 20 20 20 20 7b |sion by |0!. {| |000058f0| 0d 20 20 20 20 20 20 20 | 20 42 58 56 28 52 61 6e |. | BXV(Ran| |00005900| 67 65 64 52 64 6d 28 30 | 2c 20 6e 42 65 65 73 29 |gedRdm(0|, nBees)| |00005910| 29 20 2b 3d 20 52 41 4e | 44 28 33 29 3b 0d 20 20 |) += RAN|D(3);. | |00005920| 20 20 20 20 20 20 42 59 | 56 28 52 61 6e 67 65 64 | BY|V(Ranged| |00005930| 52 64 6d 28 30 2c 20 6e | 42 65 65 73 29 29 20 2b |Rdm(0, n|Bees)) +| |00005940| 3d 20 52 41 4e 44 28 33 | 29 3b 0d 20 20 20 20 7d |= RAND(3|);. }| |00005950| 0d 09 0d 20 20 20 20 66 | 6f 72 20 28 62 20 3d 20 |... f|or (b = | |00005960| 30 3b 20 62 20 3c 20 6e | 42 65 65 73 3b 20 62 2b |0; b < n|Bees; b+| |00005970| 2b 29 0d 20 20 20 20 7b | 0d 20 20 20 20 20 20 20 |+). {|. | |00005980| 20 09 2f 2f 20 41 67 65 | 20 74 68 65 20 61 72 72 | .// Age| the arr| |00005990| 61 79 73 2e 20 0d 20 20 | 20 20 20 20 20 20 42 58 |ays. . | BX| |000059a0| 28 31 2c 20 62 29 20 3d | 20 42 58 28 30 2c 20 62 |(1, b) =| BX(0, b| |000059b0| 29 3b 0d 20 20 20 20 20 | 20 20 20 42 59 28 31 2c |);. | BY(1,| |000059c0| 20 62 29 20 3d 20 42 59 | 28 30 2c 20 62 29 3b 0d | b) = BY|(0, b);.| |000059d0| 20 20 20 20 20 20 20 20 | 0d 20 20 20 20 20 20 20 | |. | |000059e0| 20 09 2f 2f 20 41 63 63 | 65 6c 65 72 61 74 65 2e | .// Acc|elerate.| |000059f0| 0d 20 20 20 20 20 20 20 | 20 64 78 20 3d 20 51 58 |. | dx = QX| |00005a00| 28 31 29 20 2d 20 42 58 | 28 31 2c 20 62 29 3b 0d |(1) - BX|(1, b);.| |00005a10| 20 20 20 20 20 20 20 20 | 64 79 20 3d 20 51 59 28 | |dy = QY(| |00005a20| 31 29 20 2d 20 42 59 28 | 31 2c 20 62 29 3b 0d 20 |1) - BY(|1, b);. | |00005a30| 20 20 20 20 20 20 20 09 | 0d 20 20 20 20 20 20 20 | .|. | |00005a40| 20 09 2f 2f 20 54 68 69 | 73 20 63 61 6c 63 75 6c | .// Thi|s calcul| |00005a50| 61 74 69 6f 6e 20 6f 66 | 20 74 68 65 20 74 72 75 |ation of| the tru| |00005a60| 65 20 64 69 73 74 61 6e | 63 65 20 66 72 6f 6d 20 |e distan|ce from | |00005a70| 74 68 65 20 64 78 2f 64 | 79 20 76 61 6c 75 65 73 |the dx/d|y values| |00005a80| 0d 20 20 20 20 20 20 20 | 20 09 2f 2f 20 69 73 20 |. | .// is | |00005a90| 61 6e 20 61 70 70 72 6f | 78 69 6d 61 74 69 6f 6e |an appro|ximation| |00005aa0| 20 74 68 61 74 20 61 6c | 6c 6f 77 73 20 75 73 20 | that al|lows us | |00005ab0| 74 6f 20 6b 65 65 70 20 | 65 76 65 72 79 74 68 69 |to keep |everythi| |00005ac0| 6e 67 20 69 6e 20 0d 20 | 20 20 20 20 20 20 20 09 |ng in . | .| |00005ad0| 2f 2f 20 69 6e 74 65 67 | 65 72 20 6d 61 74 68 2e |// integ|er math.| |00005ae0| 20 4f 74 68 65 72 77 69 | 73 65 20 77 65 27 64 20 | Otherwi|se we'd | |00005af0| 68 61 76 65 20 64 6f 20 | 73 71 75 61 72 65 20 72 |have do |square r| |00005b00| 6f 6f 74 20 6f 70 65 72 | 61 74 69 6f 6e 73 2e 2e |oot oper|ations..| |00005b10| 2e 0d 20 20 20 20 20 20 | 20 20 64 69 73 74 61 6e |.. | distan| |00005b20| 63 65 20 3d 20 61 62 73 | 28 64 78 29 20 2b 20 61 |ce = abs|(dx) + a| |00005b30| 62 73 28 64 79 29 3b 20 | 0d 20 20 20 20 20 20 20 |bs(dy); |. | |00005b40| 20 69 66 20 28 64 69 73 | 74 61 6e 63 65 20 3d 3d | if (dis|tance ==| |00005b50| 20 30 29 0d 20 20 20 20 | 20 20 20 20 20 20 20 20 | 0). | | |00005b60| 64 69 73 74 61 6e 63 65 | 20 3d 20 31 3b 0d 20 20 |distance| = 1;. | |00005b70| 20 20 20 20 20 20 42 58 | 56 28 62 29 20 2b 3d 20 | BX|V(b) += | |00005b80| 28 64 78 20 2a 20 73 77 | 61 72 6d 2d 3e 6d 61 78 |(dx * sw|arm->max| |00005b90| 42 65 65 41 63 63 29 20 | 2f 20 64 69 73 74 61 6e |BeeAcc) |/ distan| |00005ba0| 63 65 3b 20 20 20 20 20 | 20 20 20 20 0d 20 20 20 |ce; | . | |00005bb0| 20 20 20 20 20 42 59 56 | 28 62 29 20 2b 3d 20 28 | BYV|(b) += (| |00005bc0| 64 79 20 2a 20 73 77 61 | 72 6d 2d 3e 6d 61 78 42 |dy * swa|rm->maxB| |00005bd0| 65 65 41 63 63 29 20 2f | 20 64 69 73 74 61 6e 63 |eeAcc) /| distanc| |00005be0| 65 3b 0d 0d 20 20 20 20 | 20 20 20 20 09 2f 2f 20 |e;.. | .// | |00005bf0| 53 70 65 65 64 20 6c 69 | 6d 69 74 20 63 68 65 63 |Speed li|mit chec| |00005c00| 6b 73 2e 0d 20 20 20 20 | 20 20 20 20 69 66 20 28 |ks.. | if (| |00005c10| 42 58 56 28 62 29 20 3e | 20 73 77 61 72 6d 2d 3e |BXV(b) >| swarm->| |00005c20| 6d 61 78 42 65 65 56 65 | 6c 29 0d 20 20 20 20 20 |maxBeeVe|l). | |00005c30| 20 20 20 20 20 20 20 42 | 58 56 28 62 29 20 3d 20 | B|XV(b) = | |00005c40| 73 77 61 72 6d 2d 3e 6d | 61 78 42 65 65 56 65 6c |swarm->m|axBeeVel| |00005c50| 3b 0d 20 20 20 20 20 20 | 20 20 65 6c 73 65 20 0d |;. | else .| |00005c60| 20 20 20 20 20 20 20 20 | 09 69 66 20 28 42 58 56 | |.if (BXV| |00005c70| 28 62 29 20 3c 20 2d 73 | 77 61 72 6d 2d 3e 6d 61 |(b) < -s|warm->ma| |00005c80| 78 42 65 65 56 65 6c 29 | 0d 20 20 20 20 20 20 20 |xBeeVel)|. | |00005c90| 20 20 20 20 20 09 42 58 | 56 28 62 29 20 3d 20 2d | .BX|V(b) = -| |00005ca0| 73 77 61 72 6d 2d 3e 6d | 61 78 42 65 65 56 65 6c |swarm->m|axBeeVel| |00005cb0| 3b 0d 20 20 20 20 20 20 | 20 20 69 66 20 28 42 59 |;. | if (BY| |00005cc0| 56 28 62 29 20 3e 20 73 | 77 61 72 6d 2d 3e 6d 61 |V(b) > s|warm->ma| |00005cd0| 78 42 65 65 56 65 6c 29 | 0d 20 20 20 20 20 20 20 |xBeeVel)|. | |00005ce0| 20 20 20 20 20 42 59 56 | 28 62 29 20 3d 20 73 77 | BYV|(b) = sw| |00005cf0| 61 72 6d 2d 3e 6d 61 78 | 42 65 65 56 65 6c 3b 0d |arm->max|BeeVel;.| |00005d00| 20 20 20 20 20 20 20 20 | 65 6c 73 65 0d 20 20 20 | |else. | |00005d10| 20 20 20 20 20 09 69 66 | 20 28 42 59 56 28 62 29 | .if| (BYV(b)| |00005d20| 20 3c 20 2d 73 77 61 72 | 6d 2d 3e 6d 61 78 42 65 | < -swar|m->maxBe| |00005d30| 65 56 65 6c 29 0d 20 20 | 20 20 20 20 20 20 20 20 |eVel). | | |00005d40| 20 20 09 42 59 56 28 62 | 29 20 3d 20 2d 73 77 61 | .BYV(b|) = -swa| |00005d50| 72 6d 2d 3e 6d 61 78 42 | 65 65 56 65 6c 3b 0d 0d |rm->maxB|eeVel;..| |00005d60| 20 20 20 20 09 09 2f 2f | 20 46 69 6c 6c 20 6e 65 | ..//| Fill ne| |00005d70| 77 20 27 63 75 72 72 65 | 6e 74 27 20 70 6f 73 69 |w 'curre|nt' posi| |00005d80| 74 69 6f 6e 73 2e 0d 20 | 20 20 20 20 20 20 20 42 |tions.. | B| |00005d90| 58 28 30 2c 20 62 29 20 | 3d 20 42 58 28 31 2c 20 |X(0, b) |= BX(1, | |00005da0| 62 29 20 2b 20 42 58 56 | 28 62 29 3b 0d 20 20 20 |b) + BXV|(b);. | |00005db0| 20 20 20 20 20 42 59 28 | 30 2c 20 62 29 20 3d 20 | BY(|0, b) = | |00005dc0| 42 59 28 31 2c 20 62 29 | 20 2b 20 42 59 56 28 62 |BY(1, b)| + BYV(b| |00005dd0| 29 3b 0d 20 20 20 20 20 | 20 20 20 0d 20 20 20 20 |);. | . | |00005de0| 20 20 20 20 09 2f 2f 20 | 4b 65 65 70 20 74 72 61 | .// |Keep tra| |00005df0| 63 6b 20 6f 66 20 74 68 | 65 20 6d 69 6e 69 6d 61 |ck of th|e minima| |00005e00| 6c 20 62 6f 75 64 69 6e | 67 20 72 65 63 74 20 6f |l boudin|g rect o| |00005e10| 66 20 74 68 65 20 73 77 | 61 72 6d 20 73 6f 20 66 |f the sw|arm so f| |00005e20| 61 72 2e 0d 20 20 20 20 | 20 20 20 20 73 65 74 6d |ar.. | setm| |00005e30| 69 6e 28 42 58 28 30 2c | 62 29 2c 20 78 4d 69 6e |in(BX(0,|b), xMin| |00005e40| 29 3b 0d 20 20 20 20 20 | 20 20 20 73 65 74 6d 61 |);. | setma| |00005e50| 78 28 42 58 28 30 2c 62 | 29 2c 20 78 4d 61 78 29 |x(BX(0,b|), xMax)| |00005e60| 3b 0d 20 20 20 20 20 20 | 20 20 73 65 74 6d 69 6e |;. | setmin| |00005e70| 28 42 58 28 31 2c 62 29 | 2c 20 78 4d 69 6e 29 3b |(BX(1,b)|, xMin);| |00005e80| 0d 20 20 20 20 20 20 20 | 20 73 65 74 6d 61 78 28 |. | setmax(| |00005e90| 42 58 28 31 2c 62 29 2c | 20 78 4d 61 78 29 3b 0d |BX(1,b),| xMax);.| |00005ea0| 0d 20 20 20 20 20 20 20 | 20 73 65 74 6d 69 6e 28 |. | setmin(| |00005eb0| 42 59 28 30 2c 62 29 2c | 20 79 4d 69 6e 29 3b 0d |BY(0,b),| yMin);.| |00005ec0| 20 20 20 20 20 20 20 20 | 73 65 74 6d 61 78 28 42 | |setmax(B| |00005ed0| 59 28 30 2c 62 29 2c 20 | 79 4d 61 78 29 3b 0d 20 |Y(0,b), |yMax);. | |00005ee0| 20 20 20 20 20 20 20 73 | 65 74 6d 69 6e 28 42 59 | s|etmin(BY| |00005ef0| 28 31 2c 62 29 2c 20 79 | 4d 69 6e 29 3b 0d 20 20 |(1,b), y|Min);. | |00005f00| 20 20 20 20 20 20 73 65 | 74 6d 61 78 28 42 59 28 | se|tmax(BY(| |00005f10| 31 2c 62 29 2c 20 79 4d | 61 78 29 3b 20 20 20 0d |1,b), yM|ax); .| |00005f20| 20 20 20 20 7d 20 20 20 | 20 20 20 20 0d 0d 09 09 | } | ....| |00005f30| 2f 2f 20 73 77 61 72 6d | 52 65 63 74 20 77 69 6c |// swarm|Rect wil| |00005f40| 6c 20 6e 6f 77 20 62 65 | 20 73 65 74 20 74 6f 20 |l now be| set to | |00005f50| 74 68 65 20 6d 69 6e 69 | 6d 61 6c 20 62 6f 75 6e |the mini|mal boun| |00005f60| 64 69 6e 67 20 72 65 63 | 74 61 6e 67 6c 65 20 77 |ding rec|tangle w| |00005f70| 65 27 76 65 20 62 65 65 | 6e 20 6d 61 69 6e 74 61 |e've bee|n mainta| |00005f80| 69 6e 69 6e 67 2c 0d 09 | 09 2f 2f 20 77 68 69 63 |ining,..|.// whic| |00005f90| 68 20 77 65 20 77 61 6e | 74 20 74 6f 20 27 63 6c |h we wan|t to 'cl| |00005fa0| 69 70 27 20 62 79 20 69 | 6e 74 65 72 73 65 63 74 |ip' by i|ntersect| |00005fb0| 69 6e 67 20 69 74 20 77 | 69 74 68 20 74 68 65 20 |ing it w|ith the | |00005fc0| 73 63 72 65 65 6e 20 72 | 65 63 74 61 6e 67 6c 65 |screen r|ectangle| |00005fd0| 2c 0d 09 09 2f 2f 20 61 | 6e 64 20 77 68 69 63 68 |,...// a|nd which| |00005fe0| 20 77 65 20 66 69 6e 61 | 6c 6c 79 20 6e 65 65 64 | we fina|lly need| |00005ff0| 20 74 6f 20 63 6f 6d 62 | 69 6e 65 20 77 69 74 68 | to comb|ine with| |00006000| 20 74 68 65 20 2a 6f 6c | 64 2a 20 62 6f 75 6e 64 | the *ol|d* bound| |00006010| 69 6e 67 20 72 65 63 74 | 61 6e 67 6c 65 2c 0d 09 |ing rect|angle,..| |00006020| 09 2f 2f 20 74 6f 20 67 | 69 76 65 20 61 73 20 61 |.// to g|ive as a| |00006030| 20 72 65 73 75 6c 74 20 | 74 68 65 20 6d 69 6e 69 | result |the mini| |00006040| 6d 61 6c 20 62 6f 75 6e | 64 69 6e 67 20 72 65 63 |mal boun|ding rec| |00006050| 74 61 6e 67 6c 65 20 6f | 66 20 74 68 65 20 65 6e |tangle o|f the en| |00006060| 74 69 72 65 20 73 63 72 | 65 65 6e 0d 09 09 2f 2f |tire scr|een...//| |00006070| 20 61 72 65 61 20 74 68 | 61 74 20 68 61 73 20 62 | area th|at has b| |00006080| 65 65 6e 20 61 66 66 65 | 63 74 65 64 20 62 79 20 |een affe|cted by | |00006090| 74 68 69 73 20 73 74 65 | 70 20 6f 66 20 74 68 65 |this ste|p of the| |000060a0| 20 61 6e 69 6d 61 74 69 | 6f 6e 2e 0d 09 09 0d 20 | animati|on..... | |000060b0| 20 20 20 53 65 74 52 65 | 63 74 28 73 77 61 72 6d | SetRe|ct(swarm| |000060c0| 52 65 63 74 2c 20 78 4d | 69 6e 2d 31 2c 20 79 4d |Rect, xM|in-1, yM| |000060d0| 69 6e 2d 31 2c 20 78 4d | 61 78 2b 31 2c 20 79 4d |in-1, xM|ax+1, yM| |000060e0| 61 78 2b 31 29 3b 0d 20 | 20 20 20 53 65 63 74 52 |ax+1);. | SectR| |000060f0| 65 63 74 28 26 6d 6f 6e | 69 74 6f 72 52 65 63 74 |ect(&mon|itorRect| |00006100| 2c 20 73 77 61 72 6d 52 | 65 63 74 2c 20 73 77 61 |, swarmR|ect, swa| |00006110| 72 6d 52 65 63 74 29 3b | 0d 20 20 20 20 55 6e 69 |rmRect);|. Uni| |00006120| 6f 6e 52 65 63 74 28 6f | 6c 64 52 65 63 74 2c 20 |onRect(o|ldRect, | |00006130| 73 77 61 72 6d 52 65 63 | 74 2c 20 26 75 6e 69 6f |swarmRec|t, &unio| |00006140| 6e 52 65 63 74 29 3b 0d | 20 20 20 20 0d 20 20 20 |nRect);.| . | |00006150| 20 09 2f 2f 20 53 61 76 | 65 20 74 68 65 20 72 65 | .// Sav|e the re| |00006160| 61 6c 20 73 63 72 65 65 | 6e 20 77 6f 72 6c 64 2e |al scree|n world.| |00006170| 0d 09 47 65 74 47 57 6f | 72 6c 64 28 26 63 75 72 |..GetGWo|rld(&cur| |00006180| 72 50 6f 72 74 2c 20 26 | 63 75 72 72 44 65 76 29 |rPort, &|currDev)| |00006190| 3b 0d 09 0d 09 09 2f 2f | 20 53 77 69 74 63 68 20 |;.....//| Switch | |000061a0| 74 6f 20 74 68 65 20 6f | 66 66 73 63 72 65 65 6e |to the o|ffscreen| |000061b0| 20 77 6f 72 6c 64 2e 0d | 20 20 20 20 53 65 74 47 | world..| SetG| |000061c0| 57 6f 72 6c 64 20 28 73 | 77 61 72 6d 2d 3e 67 4d |World (s|warm->gM| |000061d0| 79 4f 66 66 47 2c 20 6e | 69 6c 29 3b 0d 20 20 20 |yOffG, n|il);. | |000061e0| 20 09 0d 20 20 20 20 09 | 2f 2f 20 45 72 61 73 65 | .. .|// Erase| |000061f0| 20 74 68 65 20 6f 6c 64 | 20 73 77 61 72 6d 20 62 | the old| swarm b| |00006200| 6f 75 6e 64 69 6e 67 20 | 72 65 63 74 61 6e 67 6c |ounding |rectangl| |00006210| 65 2e 0d 09 52 47 42 42 | 61 63 6b 43 6f 6c 6f 72 |e...RGBB|ackColor| |00006220| 28 26 73 77 61 72 6d 2d | 3e 62 61 63 6b 52 47 42 |(&swarm-|>backRGB| |00006230| 29 3b 0d 20 20 20 20 45 | 72 61 73 65 52 65 63 74 |);. E|raseRect| |00006240| 28 6f 6c 64 52 65 63 74 | 29 3b 0d 20 20 20 20 0d |(oldRect|);. .| |00006250| 20 20 20 20 09 2f 2f 20 | 44 72 61 77 20 74 68 65 | .// |Draw the| |00006260| 20 6e 65 77 20 73 77 61 | 72 6d 2c 20 66 69 72 73 | new swa|rm, firs| |00006270| 74 20 51 75 65 65 6e 2c | 20 74 68 65 6e 20 42 65 |t Queen,| then Be| |00006280| 65 73 2e 0d 20 20 20 20 | 52 47 42 46 6f 72 65 43 |es.. |RGBForeC| |00006290| 6f 6c 6f 72 28 26 71 75 | 65 65 6e 52 47 42 29 3b |olor(&qu|eenRGB);| |000062a0| 0d 20 20 20 20 4d 6f 76 | 65 54 6f 28 51 58 28 30 |. Mov|eTo(QX(0| |000062b0| 29 2c 20 51 59 28 30 29 | 29 3b 0d 20 20 20 20 4c |), QY(0)|);. L| |000062c0| 69 6e 65 54 6f 28 51 58 | 28 31 29 2c 20 51 59 28 |ineTo(QX|(1), QY(| |000062d0| 31 29 29 3b 0d 0d 20 20 | 20 20 52 47 42 46 6f 72 |1));.. | RGBFor| |000062e0| 65 43 6f 6c 6f 72 28 26 | 62 65 65 52 47 42 29 3b |eColor(&|beeRGB);| |000062f0| 0d 0d 20 20 20 20 66 6f | 72 20 28 62 20 3d 20 30 |.. fo|r (b = 0| |00006300| 3b 20 62 20 3c 20 6e 42 | 65 65 73 3b 20 62 2b 2b |; b < nB|ees; b++| |00006310| 29 0d 20 20 20 20 7b 0d | 20 20 20 20 20 20 20 20 |). {.| | |00006320| 4d 6f 76 65 54 6f 28 42 | 58 28 30 2c 20 62 29 2c |MoveTo(B|X(0, b),| |00006330| 20 42 59 28 30 2c 20 62 | 29 29 3b 0d 20 20 20 20 | BY(0, b|));. | |00006340| 20 20 20 20 4c 69 6e 65 | 54 6f 28 42 58 28 31 2c | Line|To(BX(1,| |00006350| 20 62 29 2c 20 42 59 28 | 31 2c 20 62 29 29 3b 0d | b), BY(|1, b));.| |00006360| 20 20 20 20 7d 0d 0d 09 | 09 2f 2f 20 53 77 69 74 | }...|.// Swit| |00006370| 63 68 20 62 61 63 6b 20 | 74 6f 20 74 68 65 20 72 |ch back |to the r| |00006380| 65 61 6c 20 73 63 72 65 | 65 6e 2e 20 20 20 20 0d |eal scre|en. .| |00006390| 09 53 65 74 47 57 6f 72 | 6c 64 28 63 75 72 72 50 |.SetGWor|ld(currP| |000063a0| 6f 72 74 2c 20 63 75 72 | 72 44 65 76 29 3b 09 20 |ort, cur|rDev);. | |000063b0| 20 20 09 09 0d 20 20 20 | 09 0d 09 09 2f 2f 20 52 | ... |....// R| |000063c0| 65 74 72 69 65 76 65 20 | 61 63 74 75 61 6c 20 70 |etrieve |actual p| |000063d0| 69 78 65 6c 20 6d 61 70 | 73 20 66 6f 72 20 62 6f |ixel map|s for bo| |000063e0| 74 68 20 6f 66 66 73 63 | 72 65 65 6e 20 61 6e 64 |th offsc|reen and| |000063f0| 20 72 65 61 6c 20 73 63 | 72 65 65 6e 2e 0d 09 72 | real sc|reen...r| +--------+-------------------------+-------------------------+--------+--------+ Only 25.0 KB of data is shown above.